convert epoch time to date

后端 未结 3 1892
甜味超标
甜味超标 2020-12-01 05:35

I\'ve tried a million different ways of doing this, but with no avail. Any help would be much appreciated.

long millis = getMillisFromServer();
Date date =          


        
3条回答
  •  抹茶落季
    2020-12-01 06:11

    Please take care that the epoch time is in second and Date object accepts Long value which is in milliseconds. Hence you would have to multiply epoch value with 1000 to use it as long value . Like below :-

    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");
    sdf.setTimeZone(TimeZone.getTimeZone(timeZone));
    Long dateLong=Long.parseLong(sdf.format(epoch*1000));
    

提交回复
热议问题