How to get GMT date from Unix epoch of millisecond time?
I am trying to convert unix milliseconds to gmt date, I only need hours and minutes, but the results are not correct according to online converters.
What I need
Here is my code:
public static void main(String[] args) {
long time = 1438050023;
// TimeZone timeZone = TimeZone.getTimeZone("UTC");
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(time / 1000);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("hh:mm:ss dd MM yyyy");
simpleDateFormat.setTimeZone(calendar.getTimeZone());
System.out.println(simpleDateFormat.format(calendar.getTime()));
}
Result:
03:23:58 01 01 1970
+3
source to share
2 answers
public static String ConvertMillistoDatetime(long millis) {
long second = (millis / 1000) % 60;
long minute = (millis / (1000 * 60)) % 60;
long hour = (millis / (1000 * 60 * 60)) % 24;
return String.format("%02d:%02d:%02d", hour, minute, second);
}
Try this, you can save seconds here
+1
source to share