GPS时间(以毫秒为单位)为UTC格式 [英] GPS time in millis to UTC format

查看:1105
本文介绍了GPS时间(以毫秒为单位)为UTC格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有直接方法可以将1980年1月6日开始的特定秒数转换为YYYY / MM / DD HH:mm:ss之类的UTC格式?

Is there any direct way of converting a certain amount of seconds starting on January 6th 1980 to an UTC format like YYYY/MM/DD HH:mm:ss?

编辑:这是工作代码:

private Date gpsInit;
//...
try{
        String ds = "06/01/1980";
        DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
        gpsInit = df.parse(ds);
    }
    catch(ParseException e) {
        System.out.println("Unable to parse January 6th 1980");
    }

    textField = new JFormattedTextField(format);
    textField.setText(formatUTC(min));
//...
private String formatUTC(int timeValue) {
        long diference = timeValue + gpsInit.getTime()/1000;
        String pattern = "yyyy/MM/dd HH:mm:ss";
        SimpleDateFormat utcFormat = new SimpleDateFormat(pattern);
        Date utcNow = new Date(diference*1000);
        return utcFormat.format(utcNow);
    }


推荐答案

类似于:


  1. 构造一个 Date 对象(通过 Calendar )作为 06.01.1980 00:00:00 日期

  2. 调用 getTime()获取自EPOCH以来的毫秒数

  3. 在其中添加毫秒数

  4. 构造一个新的 Date 具有该毫秒值的对象。

  5. 根据需要对其进行格式化(例如, SimpleDateFormatter

  1. Construct a Date object (via Calendar) for the 06.01.1980 00:00:00 date
  2. call getTime() to get the milliseconds since EPOCH
  3. Add your milliseconds to that
  4. Construct a new Date object with that milliseconds value.
  5. Format it however you want (SimpleDateFormatter for example)

这篇关于GPS时间(以毫秒为单位)为UTC格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆