It was discussed too many times, I know, but I can't get why the milliseconds generated by mine:
System.currentTimeMillis();
Or by:
Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTimeInMillis()
Are not equal to what I see on www.epochconverter.com?
What I need is to merely generate a String
of concrete format, but I've found out the milliseconds aren't right.
Just in case here is how I do it:
private static final String DATE_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
public static String getCurrentTimestamp() {
long time = System.currentTimeMillis();
SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN);
String lastModifiedTime = sdf.format(time);
Logger.logVerbose(TAG, "Generated timestamp is " + lastModifiedTime);
return lastModifiedTime;
}
What I finally get is just a local time, but I need the only time which is pure UTC without conjunction with my timezone.
I've even checked it with SQLite (using the SELECT strftime('%s',timestring);
) and got the correct milliseconds. Why then I got it incorrectly generated by those two statements I posted above? Thanks a lot in advance.