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).
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 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).
We can get epoch from DateTime from strftime(). Parameter: timestamp is the input datetime. $s is used to get the epoch string.
We can convert String to Date in java using parse() method of DateFormat and SimpleDateFormat classes.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With