Erlang Central

Convert Epoch Seconds to DMYHMS

Revision as of 03:48, 12 June 2007 by MataRender476 (Talk | contribs)

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