Java – convert timestamp to UTC time zone
•
Java
public static long getCurrentEpochTimeStamp(String timeStamp) throws Exception {
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 the epoch current timestamp, which I need to convert to UTC time zone
Solution
Set the time zone to the simpledateformat object
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码