4
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.

2 Answers 2

6

Set time zone to your SimpleDateFormat object.

sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
0
2

Date is always in UTC and you cannot convert it. The problem is how to parse string representation. If timeStamp contains timezone, then pattern "yyyy-MM-dd'T'HH:mm:ss'.0Z'" is incorrect because it does not parse timezone. It should be "yyyy-MM-dd'T'HH:mm:ssZ" if timezone is in RFC 822 format, use X instead of Z if timezone is in ISO 8601. See SimpleDateFormat API

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.