Anuj Mehta
Anuj Mehta

Reputation: 1136

Java 8 : How to convert timestamp to long

I am writing a back-end service and receive timestamp as shown below

Instant timestamp = Instant.now().plusMillis(offset);
bodyObject.put("timestamp", DateTimeFormatter.ISO_INSTANT.format(timestamp));

Now at my service end I want to convert this timestamp into "Long" data type for my further processing. Please guide me how can I achieve this?

Upvotes: 2

Views: 3122

Answers (1)

Anuj Mehta
Anuj Mehta

Reputation: 1136

I am converting the timestamp format to Instant and then using getEpochSecond() method to get seconds

Instant instant = Instant.from(DateTimeFormatter.ISO_INSTANT.parse(format));
instant.getEpochSecond();

Upvotes: 2

Related Questions