user288231 user288231 - 7 days ago 5
Android Question

Android Convert Unix Time to GMT time

I'm having trouble in converting a unix time into GMT.

I have the following code, but I would like to know how to vice versa it.

public static String GetUnixTime()
{
Calendar calendar = Calendar.getInstance();
long now = calendar.getTimeInMillis();

return Long.toString(now);
}

Answer

Try this

Date d = new Date(1308670980000L);
SimpleDateFormat f = new SimpleDateFormat("dd.MM.yyyy,HH:mm");
f.setTimeZone(TimeZone.getTimeZone("GMT");
String s = f.format(d);