将时间戳转换为UTC时区

Sun*_*oom 3 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();
}
Run Code Online (Sandbox Code Playgroud)

此方法返回纪元当前时间戳,我需要将其转换为UTC时区。

Sur*_*tta 5

为您的SimpleDateFormat 对象设置时区。

sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
Run Code Online (Sandbox Code Playgroud)