时区问题

作者: 云心随风 | 来源:发表于2018-01-18 15:50 被阅读0次

    //获取格林威治标准时间
    public void getGMTTime() {
    //mothed 2
    TimeZone gmtTime = TimeZone.getTimeZone("GMT");
    Date date = new Date();
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    format.setTimeZone(gmtTime);
    System.out.println("GMT Time: " + format.format(date));

        //method 2
        Calendar calendar1 = Calendar.getInstance();
        calendar1.setTimeZone(gmtTime);
        //System.out.println(calendar1.getTime());    //时区无效
        //System.out.println(calendar1.getTimeInMillis()); //时区无效
        System.out.println("GMT hour = " + calendar1.get(Calendar.HOUR));
    }

    相关文章

      网友评论

        本文标题:时区问题

        本文链接:https://www.haomeiwen.com/subject/upswoxtx.html