Convert Epoch seconds to date and time format in Java

In case you’re restricted to legacy java.util.Date and java.util.Calendar APIs, you need to take into account that the timestamps are interpreted in milliseconds, not seconds. So you first need to multiply it by 1000 to get the timestamp in milliseconds. long seconds = 1320105600; long millis = seconds * 1000; This way you can feed … Read more

Android difference between two dates in seconds

You can turn a date object into a long (milliseconds since Jan 1, 1970), and then use TimeUnit to get the number of seconds: long diffInMs = endDate.getTime() – startDate.getTime(); long diffInSec = TimeUnit.MILLISECONDS.toSeconds(diffInMs); Edit: -Corrected the name of the variable diffInMs which was written diffInM(i)s in the second line.

Java getHours(), getMinutes() and getSeconds()

Try this: Calendar calendar = Calendar.getInstance(); calendar.setTime(yourdate); int hours = calendar.get(Calendar.HOUR_OF_DAY); int minutes = calendar.get(Calendar.MINUTE); int seconds = calendar.get(Calendar.SECOND); Edit: hours, minutes, seconds above will be the hours, minutes and seconds after converting yourdate to System Timezone!

Converting milliseconds to minutes and seconds with Javascript

function millisToMinutesAndSeconds(millis) { var minutes = Math.floor(millis / 60000); var seconds = ((millis % 60000) / 1000).toFixed(0); return minutes + “:” + (seconds < 10 ? ‘0’ : ”) + seconds; } millisToMinutesAndSeconds(298999); // “4:59” millisToMinutesAndSeconds(60999); // “1:01” As User HelpingHand pointed in the comments the return statement should be: return ( seconds == 60 … Read more

How to convert an NSTimeInterval (seconds) into minutes

Brief Description The answer from Brian Ramsay is more convenient if you only want to convert to minutes. If you want Cocoa API do it for you and convert your NSTimeInterval not only to minutes but also to days, months, week, etc,… I think this is a more generic approach Use NSCalendar method: (NSDateComponents *)components:(NSUInteger)unitFlags … Read more