[erlang-questions] Time zone

Chandru chandrashekhar.mullaparthi@REDACTED
Mon Dec 11 12:25:15 CET 2006


Hi,

Is there a way to get the time zone configured on a machine without
resorting to hacks.

It'll be nice to have something like:

calendar:time_zone().
OR
erlang:system_info(time_zone).

Example from yaws_log.erl below.

zone() ->
    Time = erlang:universaltime(),
    LocalTime = calendar:universal_time_to_local_time(Time),
    DiffSecs = calendar:datetime_to_gregorian_seconds(LocalTime) -
calendar:datetime_to_gregorian_seconds(Time),
    zone((DiffSecs/3600)*100).

%% Ugly reformatting code to get times like +0000 and -1300

zone(Val) when Val < 0 ->
    io_lib:format("-~4..0w", [trunc(abs(Val))]);
zone(Val) when Val >= 0 ->
    io_lib:format("+~4..0w", [trunc(abs(Val))]).

cheers
Chandru



More information about the erlang-questions mailing list