Unix Epoch Timestamp to Human readable Date time and back conversions

2013-12-17T21:44:56

In Erlang, i can get the Unix Epoc Timestamp by the code below:

{MegaSecs, Secs, MicroSecs} = now().
UnixTime = MegaSecs * 1000000 + Secs.

OR (as suggested by some sites)

calendar:datetime_to_gregorian_seconds(calendar:universal_time())-719528*24*3600.

However that conversion has occured for the result of erlang:now(). What if i have a given date time value in the format: "YYYY-MM-DD HH:MI:SS" e.g. "2012-12-30 15:13:40" The time being in 24 hour format.
This website gives the complete picture of what i need to be able to do in erlang.

How can i interchangeably convert from human readable formats to unix epoch timestamps and vice versa "at will", in my code. Such that if in my programs i store the timestamps as Unix Epochs, at the time of reading them, i can retrieve the human readable format automatically from the unix timestamp value or viceversa.

Copyright License:
Author:「Muzaaya Joshua」,Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.
Link to:https://stackoverflow.com/questions/20635830/unix-epoch-timestamp-to-human-readable-date-time-and-back-conversions

About “Unix Epoch Timestamp to Human readable Date time and back conversions” questions

Copyright License:Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.