-3

Is there some function in Java, for parsing timestamp to decimal?

Input: 2023-07-04 00:00:00.0

Expected output: 1687771449497

Kate Quinn
  • 29
  • 4
  • 2023-07-04 00:00:00.0 is certainly not 1687771449497ms since epoch. – Sweeper Jul 03 '23 at 06:45
  • its just an example, not right conversion.. – Kate Quinn Jul 03 '23 at 06:46
  • Refer parsing - https://stackoverflow.com/q/8854780/11566161 and converting - https://stackoverflow.com/q/11871120/11566161 – Shri Hari L Jul 03 '23 at 06:46
  • I think we don't have a single direct method() to do this. – Shri Hari L Jul 03 '23 at 06:47
  • 1
    "it is just an example" - then we need to know what the "decimal" is expected to be representing (milliseconds since 1970-01-01T00:00:00Z is one standard, but can we assume that without having a valid example?) || also what type is the input (`String`, `Timestamp`, ...)? – user16320675 Jul 03 '23 at 07:21

1 Answers1

1

If you're using LocalDateTime for you timestamp representation in Java code, so you can you the following approach to convert timestamp into epoch millis:

LocalDateTime localDateTime = LocalDateTime.of(2023, 7, 4, 0, 0);
ZonedDateTime zdt = ZonedDateTime.of(localDateTime, ZoneId.systemDefault());
long millis = zdt.toInstant().toEpochMilli();
Anton Tokmakov
  • 689
  • 4
  • 14