Get date representation in seconds?

后端 未结 4 1483
误落风尘
误落风尘 2020-12-16 13:53

I am using an API which requires a date parameter as a number of seconds, an int.

My problem is that I currently store this time in java.util.dat

4条回答
  •  清酒与你
    2020-12-16 14:38

    Since Java 8 and onwards there's this elegant method which returns the Epoch time in seconds (seconds since 0:00:0 January 1st 1970). You can then store this value as an numeric value: a "long" in this case.

    long timestamp = java.time.Instant.now().getEpochSecond();

提交回复
热议问题