now() -> now_to_tz

Pierpaolo BERNARDI <>
Thu Feb 27 18:10:17 CET 2003


From: "Pierpaolo BERNARDI" <>

> local_tz() ->
>     UT = calendar:universal_time(),
>     LT = calendar:universal_time_to_local_time(UT),
>     (calendar:datetime_to_gregorian_seconds(LT) -
>  calendar:datetime_to_gregorian_seconds(UT)).
> 
> now_to_local_time_tz({Mega,Sec,Micro},TZ) ->
>     TZSec = TZ * 3600 - local_tz(),
>     calendar:now_to_local_time({Mega,Sec+TZSec,Micro}).

Oops, I missed the (obvious) function calendar:now_to_datetime.
So the above can be simplified to:

now_to_local_time_tz({Mega,Sec,Micro},TZ) ->
    calendar:now_to_datetime({Mega,Sec+TZ*3600,Micro}).

P.




More information about the erlang-questions mailing list