Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Date String into Epoch in Java [duplicate]

Is there a way to convert a given Date String into Milliseconds (Epoch Long format) in java? Example : I want to convert

public static final String date = "04/28/2016"; 

into milliseconds (epoch).

like image 632
Ashley Avatar asked Apr 21 '16 14:04

Ashley


People also ask

How do you convert date String to epoch time?

Convert from human-readable date to epochlong epoch = new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse("01/01/1970 01:00:00").getTime() / 1000; Timestamp in seconds, remove '/1000' for milliseconds. date +%s -d"Jan 1, 1980 00:00:01" Replace '-d' with '-ud' to input in GMT/UTC time.

What is epoch date format Java?

What is epoch time? The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z).

How do I get epoch from DateTime?

We can get epoch from DateTime from strftime(). Parameter: timestamp is the input datetime. $s is used to get the epoch string.

Can we convert String to date in Java?

We can convert String to Date in java using parse() method of DateFormat and SimpleDateFormat classes.


1 Answers

The getTime() method of the Date class returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.

like image 139
Paul Ostrowski Avatar answered Oct 06 '22 00:10

Paul Ostrowski