[erlang-questions] Working with dates.

Per Hedeland < >
Mon Jul 16 11:32:19 CEST 2007

```Michael McDaniel < > wrote:
>
>On Sun, Jul 15, 2007 at 06:44:50PM -0700, Michael McDaniel wrote:
>> On Sun, Jul 15, 2007 at 06:40:45PM -0700, Michael McDaniel wrote:
>> >
>> > On Sun, Jul 15, 2007 at 06:39:18PM -0500, Julio César Carrascal Urquijo (MCTS) wrote:
>> > > Hi,
>> > >
>> > > Two quick questions on functionality that I couldn't find on the documentation:
>> > >
>> > > 1) Are there functions in OTP to convert unix timestamp <--> the tuple
>> > > format used in Erlang?
>> > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>> >
>> >  ( )174> Seconds = os:cmd("../c/time").
>> >  "1184549721"
>> >  ( )175> {Days, Time} = calendar:seconds_to_daystime( list_to_integer(Seconds) ).
>> >  {13710,{1,35,21}}
>> >  ( )176> Date = calendar:gregorian_days_to_date( Days ).
>> >  {37,7,15}
>> ^^^^^^^^^^^^^^
>> ^^^^^^^^^^^^^^
>>   oops, 37 ? something's not right, obviously...
>> ~M
>^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
>  Ok, because Unix time starts @1970 and Gregorian starts, apparently, at 0.
>  Adding 1970+37 = 2007 but I wonder if there would be an "off by 1" somewhere

Assuming that Julio meant what you think with "unix timestamp", i.e. the
thing returned by the time() function, the way to go would be to first
convert it to erlang:now() form:

1> T = 1184549721.
1184549721
2> Now = {T div 1000000, T rem 1000000, 0}.
{1184,549721,0}

And depending on what Julio meant with "the tuple format used in Erlang",
that may be the answer.:-) Otherwise go on to use either

3> calendar:now_to_universal_time(Now).
{{2007,7,16},{1,35,21}}

or

4> calendar:now_to_local_time(Now).
{{2007,7,16},{3,35,21}}

- and then you can use whatever else you need from the calendar module.

--Per Hedeland

```
{"ft_lang_label":"__label__en","ft_lang_prob":0.6188926,"math_prob":0.9148598,"size":1870,"snap":"2019-26-2019-30","text_gpt3_token_len":608,"char_repetition_ratio":0.15702036,"word_repetition_ratio":0.037671234,"special_character_ratio":0.47272727,"punctuation_ratio":0.23295455,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9827572,"pos_list":[0,1,2,3,4,5,6,7,8,9,10],"im_url_duplicate_count":[null,1,null,1,null,3,null,3,null,3,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-06-16T00:48:29Z\",\"WARC-Record-ID\":\"<urn:uuid:86cc0a1a-9c4c-4ef7-9323-b179eb85891f>\",\"Content-Length\":\"5175\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:ab3a4cb7-3eb9-40b8-b930-2de31c6017c7>\",\"WARC-Concurrent-To\":\"<urn:uuid:0b9cdac7-80fe-4285-9d02-8135fd87dae9>\",\"WARC-IP-Address\":\"192.121.151.106\",\"WARC-Target-URI\":\"http://erlang.org/pipermail/erlang-questions/2007-July/027898.html\",\"WARC-Payload-Digest\":\"sha1:PLWH2B5TWGNIYD66EA2DEWIRVP7RODCN\",\"WARC-Block-Digest\":\"sha1:UF6SPGYYLAFL2X4XLXGNNMYS6CSP7EY3\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-26/CC-MAIN-2019-26_segments_1560627997508.21_warc_CC-MAIN-20190616002634-20190616024634-00453.warc.gz\"}"}