不知何故,解析日期时间字符串并将其转换为纪元后的毫秒数在不同环境中的工作方式有所不同。时区之类的东西似乎有问题。理论上,该字符串应表示自纪元以来的 0 秒:“1970-01-01T00:00:00Z”
实际上,在开发人员机器上,这个时间神秘地是 30 分钟(18000000 毫秒)。
/**
* This really ought to return 0, but locally it returns 30 minutes worth of milliseconds.
* @return The milliseconds since the common epoch. Really ought to be zero, but isn't always.
*/
public long determineMysteriousMachineTimeDelta() {
String strDateOfEpochStart = "1970-01-01T00:00:00Z";
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
Date dateStartOfEpoch = null;
try {
dateStartOfEpoch = format.parse(strDateOfEpochStart);
} catch (ParseException e) {
return -1;
}
return dateStartOfEpoch.getTime();
}
Run Code Online (Sandbox Code Playgroud)
谢谢!