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?
EDIT: Here is the code working:
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);
}
Something like:
Date
object (via Calendar
) for the 06.01.1980 00:00:00
date getTime()
to get the milliseconds since EPOCH Date
object with that milliseconds value. SimpleDateFormatter
for example)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.