小编Ada*_*ise的帖子

为什么通过 SimpleDateFormat 解析时 Java 纪元时间会减少 30 分钟

不知何故,解析日期时间字符串并将其转换为纪元后的毫秒数在不同环境中的工作方式有所不同。时区之类的东西似乎有问题。理论上,该字符串应表示自纪元以来的 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)

谢谢!

java epoch simpledateformat

0
推荐指数
1
解决办法
82
查看次数

标签 统计

epoch ×1

java ×1

simpledateformat ×1