GPS时间毫秒到UTC格式

Rom*_*dgz 1 java swing date

是否有任何直接的方式将从1980年1月6日开始的一定时间转换为UTC格式,如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);
    }
Run Code Online (Sandbox Code Playgroud)

Nim*_*Nim 7

就像是:

  1. 为日期构造一个Date对象(via Calendar)06.01.1980 00:00:00
  2. getTime()从EPOCH开始调用以获得毫秒数
  3. 添加你的毫秒数
  4. Date使用该毫秒值构造一个新对象.
  5. 根据需要格式化(SimpleDateFormatter例如)