To convert a date from string to Unix time, I can use date --date "2012-02-13" +%s
.
How do I do the opposite, from Unix time to string?
We can convert date to timestamp using the Timestamp class which is present in the SQL package. The constructor of the time-stamp class requires a long value. So data needs to be converted into a long value by using the getTime() method of the date class(which is present in the util package).
You can use date --date @datetime
:
[foo@bar ~]$date --date "2012-02-13" +%s 1329055200 [foo@bar ~]$date --date @1329055200 Mon Feb 13 00:00:00 EST 2012 [foo@bar ~]$date --date @1329055200 +"%Y-%m-%d" 2012-02-13
I'm not sure where the '@xxxx' is documented though!
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