Skip to content
Newer
Older
100644 20 lines (15 sloc) 728 Bytes
d91bd2e @rodjek Bit of code to print out the timezone in (\|+\-)\d+ form
authored Apr 19, 2010
1 % timezone code from http://www.erlang.org/pipermail/erlang-questions/2006-December/024289.html
2 % modified to return the timezone as as string
3
4 -module(timezone).
5 -export([zone/0]).
6
7 zone() ->
8 Time = erlang:universaltime(),
9 LocalTime = calendar:universal_time_to_local_time(Time),
10 DiffSecs = calendar:datetime_to_gregorian_seconds(LocalTime) -
11 calendar:datetime_to_gregorian_seconds(Time),
12 zone((DiffSecs/3600)*100).
13
14 %% Ugly reformatting code to get times like +0000 and -1300
15
16 zone(Val) when Val < 0 ->
17 binary_to_list(erlang:iolist_to_binary(io_lib:format("-~4..0w", [trunc(abs(Val))])));
18 zone(Val) when Val >= 0 ->
19 binary_to_list(erlang:iolist_to_binary(io_lib:format("+~4..0w", [trunc(abs(Val))]))).
Something went wrong with that request. Please try again.