[erlang-questions] formatting timestamps

Antoine Koener antoine.koener@REDACTED
Mon Jun 13 18:49:57 CEST 2011


On Mon, Jun 13, 2011 at 6:47 PM, Chris Hicks
<silent_vendetta@REDACTED> wrote:
> You're just going to have to do it yourself:
> {{Year, Month, Day}, {Hour, Minute, Second}} = erlang:universaltime(), %% Or
> erlang:localtime()
> Y = erlang:integer_to_list(Year),
> ...
> Formatted_date = lists:concat([Y, "-", Mo, "-", D, " ", H, ":", Mi, ":", S,
> ".", Whatever_else_here]),
> ...
> Not saying that is the most efficient way to do it but it would get you what
> you are looking for.
> Chris Hicks.

	{_, _, Usec} = Now = erlang:now(),
	{{Y, Mo, D}, {H, Mi, S}} = calendar:now_to_datetime(Now),
	Stamp =  io_lib:format("~4.4.0w-~2.2.0w-~2.2.0wT~2.2.0w:~2.2.0w:~2.2.0w.~6.6.0w
", [ Y, Mo, D, H, Mi, S, Usec ]),

...

	Log = iolist_to_binary( [ Stamp,
			[ [ <<" ">>, X, <<" ">> ] || X <- [ Login ] ],
			io_lib:format(Format, lists:map( fun filter/1, Args)), Exe, <<"\n">> ]),

Extracted from old code.

>
>> From: joelr1@REDACTED
>> Date: Mon, 13 Jun 2011 20:30:11 +0400
>> To: qrilka@REDACTED
>> CC: erlang-questions@REDACTED
>> Subject: Re: [erlang-questions] formatting timestamps
>>
>>
>> On Jun 13, 2011, at 8:08 PM, Kirill Zaborsky wrote:
>>
>> > Maybe https://github.com/daleharvey/dh_date will do the trick?
>>
>> I don't think so, e.g.
>>
>> %% This module formats erlang dates in the form
>> %% {{Year, Month, Day}, {Hour, Minute, Second}}
>>
>> --------------------------------------------------------------------------
>> - for hire: mac osx device driver ninja, kernel extensions and usb drivers
>> ---------------------+------------+---------------------------------------
>> http://wagerlabs.com | @wagerlabs | http://www.linkedin.com/in/joelreymont
>> ---------------------+------------+---------------------------------------
>>
>>
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>



More information about the erlang-questions mailing list