Convert Unix Date to Timestamp You have to combine the -d option and the %s option for converting the unix date to timestamp.
Answer: Use the Date. now() Method You can simply use the JavaScript Date. now() method to generate the UTC timestamp in milliseconds (which is the number of milliseconds since midnight Jan 1, 1970).
Convert from human-readable date to epoch long 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.
Unix time is a way of representing a timestamp by representing the time as the number of seconds since January 1st, 1970 at 00:00:00 UTC.
In Linux or MacOS you can use:
date +%s
where
+%s
, seconds since 1970-01-01 00:00:00 UTC. (GNU Coreutils 8.24 Date manual)Example output now 1454000043.
in Ruby:
>> Time.now.to_i
=> 1248933648
curl icanhazepoch.com
Basically it's unix timestamps as a service (UTaaS)
In python add the following lines to get a time stamp:
>>> import time
>>> time.time()
1335906993.995389
>>> int(time.time())
1335906993
$ date +%s.%N
where (GNU Coreutils 8.24 Date manual)
+%s
, seconds since 1970-01-01 00:00:00 UTC+%N
, nanoseconds (000000000..999999999) since epoch Example output now 1454000043.704350695
.
I noticed that BSD manual of date
did not include precise explanation about the flag +%s
.
In Perl:
>> time
=> 1335552733
The unix 'date' command is surprisingly versatile.
date -j -f "%a %b %d %T %Z %Y" "`date`" "+%s"
Takes the output of date
, which will be in the format defined by -f, and then prints it out (-j says don't attempt to set the date) in the form +%s, seconds since epoch.
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