Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert timestamp to UTC timezone

Tags:

java

timezone

public static long getCurrentEpochTimeStamp(String timeStamp) throws Exception {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'.0Z'");
    Date date = sdf.parse(timeStamp);
    return date.getTime();
}

This method returns epoch current timestamp, I need to convert this to UTC timezone.

like image 703
Sunset Bloom Avatar asked Feb 16 '23 01:02

Sunset Bloom


1 Answers

Set time zone to your SimpleDateFormat object.

sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
like image 193
Suresh Atta Avatar answered Feb 18 '23 13:02

Suresh Atta