美文网首页
格式时间转UTC时间

格式时间转UTC时间

作者: Leon丶l | 来源:发表于2017-11-12 19:36 被阅读0次

格式时间转UTC时间

最近项目里面 用到一个 把给定格式的时间转换成UTC时间 ,话不多说!直接上代码.

public void dateChange() throws ParseException {
        String str="2010-5-27 12:10:12";
        SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date =sdf.parse(str);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int zoneOffset = calendar.get(Calendar.ZONE_OFFSET);
        int dstOffset = calendar.get(Calendar.DST_OFFSET);
        calendar.add(Calendar.MILLISECOND, -(zoneOffset + dstOffset));
        long timeInMillis = calendar.getTimeInMillis();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
        System.out.println(df.format(timeInMillis));
    }

相关文章

  • 格式时间转UTC时间

    格式时间转UTC时间 最近项目里面 用到一个 把给定格式的时间转换成UTC时间 ,话不多说!直接上代码.

  • UTC 时间格式

  • 时间格式 GMT UTC

    历史来源 1)格林威治标准时间GMT 十七世纪,格林威治皇家天文台为了海上霸权的扩张计画而进行天体观测。1675年...

  • 本地时间转UTC

    方法一:使用new Date() 方法二:使用moment.js

  • UTC转本地时间

    第一个是类的方法实现,第二个是函数方式。推荐函数方式: 第三个是使用moment.js

  • 本地时间转UTC

    GMT格林尼治标准时间,这个中学地理上学过。地球自传一圈是一天,公转一圈是一年。这个是早期的一种度量标准,各个地方...

  • UTC转本地时间

  • [php]时间转化

    UTC时间 转 正常时间 13位时间戳 转 正常时间

  • Unix 时间戳转 UTC 时间

    说明 在最近的项目中,时间数据是以秒的形式展现的,需要将时间转换成 UTC + 0800 的形式,才有了如下代码。...

  • Linux上和日期时间相关的常用命令

    获取当前时间 UTC和本地时间相互转换 Local -> UTC UTC -> Local 这也包括任何时区转UT...

网友评论

      本文标题:格式时间转UTC时间

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