Cannot convert from java Double to java Date

前端 未结 2 1818
滥情空心
滥情空心 2021-01-29 06:50

I am having an issue with converting a double to a Java date object in the format: yyyy-MM-dd HH:mm:ss

I have tried to convert this double value to a long value then ins

2条回答
  •  醉话见心
    2021-01-29 07:21

    Assuming that this floating point value is seconds past the Unix Epoch of 1 Jan 1970 0:00 GMT, this will provide a conversion to a LocalDateTime with that offset:

    LocalDateTime localDateTime = LocalDateTime.ofEpochSecond(
                    Double.valueOf(1.511554592277516E9).longValue(), 0, ZoneOffset.UTC);
    System.out.println(localDateTime);
    

    I leave converting this to a Date as an exercise for the reader.

提交回复
热议问题