TZ determination

Bruce Fitzsimons <>
Tue Mar 11 06:09:44 CET 2003

Can anyone suggest some cleaner, more efficient code than this for
determining the offset from UTC/GMT? I *know* the bif's have access to this
information, but I can't see any way to get it out. It just seems awful to
have to reverse-engineer the difference, and its certainly inefficient.

Suggestions on how to better drive io_lib would be appreciated too - I ended
up with 0-100 under some formatting/padding combinations, which seemed like
a bug.

zone() ->
    Time = erlang:universaltime(),
    LocalTime = calendar:universal_time_to_local_time(Time),
    DiffSecs = calendar:datetime_to_gregorian_seconds(LocalTime) -

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

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))]).


More information about the erlang-questions mailing list