How can I convert minutes from Unix timestamp to date and time in java? For example, timestamp 1372339860
correspond to Thu, 27 Jun 2013 13:31:00 GMT
.
I want to convert 1372339860
to 2013-06-27 13:31:00 GMT
.
Edit: Actually I want it to be according to US timing GMT-4, so it will be 2013-06-27 09:31:00
.
DateTime whatever = new DateTime(yourunixtimestampaslong * 1000L, DateTimeZone.UTC);
if you use JodaTime. OrDateTime whatever = new DateTime(yourunixtimestampaslong * 1000L, DateTimeZone.forOffsetHours(-4));
for your second example. Javadoc here – Hornmadprivate String getDateString(long timeInMilliseconds) { SimpleDateFormat formatter = new SimpleDateFormat("EEE, d MMM yyyy 'at' HH:mm:ss z"); return formatter.format(timeInMilliseconds); }
– Cockspur