1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| public static String timestampToString(double timestamp)
{
if(timestamp==0) return "0";
double utc = timestamp - (2208988800.0);
// milliseconds
long ms = (long) (utc * 1000.0);
Date date = new Date(ms);
String putTime = "";
Calendar cal = Calendar.getInstance();
cal.setTime(date);
TimeZone tz = TimeZone.getTimeZone("GMT+1");
cal.setTimeZone(tz);
int day = cal.get(Calendar.DAY_OF_MONTH);
int month = cal.get(Calendar.MONTH)+1;//+1 because cal.month begin to 0 (not others)
int year = cal.get(Calendar.YEAR);
int hour24 = cal.get(Calendar.HOUR_OF_DAY); // 0..23
int min = cal.get(Calendar.MINUTE); // 0..59
int sec = cal.get(Calendar.SECOND);
putTime= setTo2Digits(year).concat("/").concat(setTo2Digits(month)).concat("/").concat(setTo2Digits(day)).concat(",").concat(setTo2Digits(hour24)).concat(":").concat(setTo2Digits(min)).concat(":").concat(setTo2Digits(sec));
return putTime;
} |
Partager