Erlang Central

Convert Epoch Seconds to DMYHMS

Revision as of 19:05, 10 June 2007 by MataRender476 (Talk | contribs)

cheap diazepam cheap xenical nokia ringtones qwest ringtones zanaflex online diazepam online verizon ringtones free motorola ringtones order lortab prozac online ericsson ringtones but ortho cheap cyclobenzaprine cheap celexa free ringtones phentermine free cool ringtones cheap prozac free qwest ringtones cialis online sprint ringtones nexium online real ringtones sagem ringtones tracfone ringtones free nokia ringtones free punk ringtones mp3 ringtones sony ringtones ativan online but hgh free midi ringtones alltel ringtones cheap flexeril sony ericsson ringtones motorola ringtones vicodin online free tracfone ringtones buy soma levitra online free motorola ringtones cheap didrex cheap sildenafil pharmacy online online zoloft online hydrocodone online free sony ringtones cingular ringtones viagra buy paxil ambien online buy lortab order hydrocodone vigrx online cheap ativan hgh online sildenafil online buy viagra ortho online nextel ringtones lisinopril free funny ringtones free sony ericsson ringtones buy vicodin hydrocodone order ativan mono ringtones clonazepam levitra free sprint ringtones cialis online sony ringtones cheap levitra zanaflex online phentermine celexa online ultracet online wwe ringtones free sharp ringtones buy norco soma online cheap ultracet free cingular ringtones cheap adipex cheap xenical cheap albuterol cheap tenuate cheap ortho free music ringtones sagem ringtones cheap lisinopril meridia online cheap propecia cheap vigrx cheap diethylpropion cheap albuterol mp3 ringtones meridia online free ringtones cheap ultram soma online cheap lortab cheap sildenafil free nextel ringtones cheap lorazepam free funny ringtones diethylpropion online free ringtones funny ringtones cingular ringtones cheap soma nokia ringtones clonazepam online zyban online clomid online buy prozac online valium order lisinopril meridia online buy tramadol sharp ringtones free midi ringtones flexeril online real ringtones celexa online zoloft online free nextel ringtones ericsson ringtones free music ringtones mtv ringtones order ultram buy valium viagra online lorazepam online cheap cialis cheap phentermine buy nexium samsung ringtones cheap norco meridia online sprint ringtones buy rivotril order carisoprodol carisoprodol online cyclobenzaprine online free qwest ringtones free qwest ringtones cheap fioricet verizon ringtones punk ringtones cheap hoodia pharmacy online online tracfone ringtones tramadol cheap rivotril tramadol online didrex online cheap fioricet music ringtones cheap albuterol free nokia ringtones buy viagra buy alprazolam buy xenical pharmacy online online free funny ringtones order zanaflex free ericsson ringtones cyclobenzaprine online adipex online cheap xanax free alltel ringtones free qwest ringtones ultram online sonyericsson ringtones free samsung ringtones cheap lortab free mono ringtones free samsung ringtones zyban online cheap celexa free funny ringtones wwe ringtones cheap rivotril but clomid buy fioricet buy hgh cheap lipitor cheap hoodia clonazepam online cool ringtones tenuate online cheap vicodin real ringtones free sonyericsson ringtones buy hoodia buy tramadol nextel ringtones cheap alprazolam ambien online == Problem ==

You have a date and time in Erlang Epoch seconds (i.e., Gregorian calendar year 0 seconds), and you want to calculate the individual DMYHMS values from it.


In recipe TimeToday we did exactly this but only for the current date. How about if we wanted to get the date, and time (DMYHMS) associated to a particular number of seconds? Once more we would use gre.

1> Seconds = 1083022458.
2> DateTime = calendar:gregorian_seconds_to_datetime(Seconds).
3> {{Year, Month, Day}, {Hour, Min, Sec}} = DateTime.
4> io:fwrite("Today's Date is ~2B/~2B/~4..0B ~2B:~2.10.0B:~2.10.0B\n",
4> [Month, Day, Year, Hour, Min, Sec]).
Today's Date is  4/26/0034 23:34:18

In recipe TimeToday we discussed how to convert a date structure to a string. Convert in the opposite direction is also possible, and useful. Unfortunately, there is not a lot of built-in Erlang plumbing to do so. However, if we are very sure of the format we can easily extract the data we need using Erlang's ever-helpful io and io_lib modules:

5> Some_Date_String = "2004-04-26T18:26:18-0500".
6> {ok, [YYY,MMM,DD,HH,MM,SS,ZZ],_} = 
6> io_lib:fread("~4d-~2d-~2dT~2d:~2d:~2d-~4d", Some_Date_String).