i have this code, i need show only hours:min:sec, any help?
String var = "1429174464829"; (this is time in System.currentTimeMillis() )
String p = "HH:mm:ss";
SimpleDateFormat f = new SimpleDateFormat(p);
long t = var - System.currentTimeMillis();
String result = f.format(new Date(t));
in example String var, is 1 hours higher than System.currentTimeMillis()
result problem
EDIT: i obtain: result = 21:59:00
thanks
解决方案
There is some time zone issue. we have to specify time zone with SimpleDateFormat. It gives result after adding time difference of your system time zone with standard UTC time zone. By default it takes your local system time zone.
String var = "1429174464829"; (this is time in System.currentTimeMillis() )
String p = "HH:mm:ss";
SimpleDateFormat f = new SimpleDateFormat(p);
f.setTimeZone(TimeZone.getTimeZone("UTC"));
long t = long.parseLong(var) - System.currentTimeMillis();
String result = f.format(new Date(t));