[erlang-bugs] erlang:now() and erlang:localtime() return different results

Patrik Nyblom <>
Fri Apr 5 12:27:27 CEST 2013


On 04/05/2013 11:41 AM, Simon Smithies wrote:
> Hi,
>
> Erlang newbie here ...
>
> I have two Debian linux VPSs, both largely identical except for Erlang 
> versions, running in Virtuozzo containers with the same provider.
>
> On the VPS running Erlang R14B04, erlang:now() and erlang:localtime() 
> return identical results (as they do on my local machine, and some 
> others we've tried):
> 1> {calendar:now_to_local_time(erlang:now()), erlang:localtime()}.
> {{{2013,4,5},{22,12,57}},{{2013,4,5},{22,12,57}}}
>
> On the other VPS however, running Erlang R15B01, I get different results:
> 1> {calendar:now_to_local_time(erlang:now()), erlang:localtime()}.
> {{{2013,4,5},{22,35,29}},{{2013,4,5},{22,30,29}}}
>
> As background, I'm running Zotonic on both VPSs; on the R15B01 machine 
> Zotonic is being regularly restarted by the heart process -- every 5 
> minutes. Have been talking to the Zotonic people about this, and in 
> the absence of a better explanation, we're thinking this time 
> difference might be the cause.
>
This has probably nothing to do with the windows bug. If the two values 
(now() and localtime()) differ, it's usually because the wall clock time 
on the system has been adjusted after Erlang was started. (by NTP or a 
manual time adjustment). If the system restarts, it may have a slightly 
skewed time at start and then it's adjusted by some means. erlang:now() 
has to slowly adapt to the new world if you set the time. The realtime 
properties requires that time in the system does not jump, but you would 
not want now() and localtime() to move away from each other, why now() 
slowly adjusts. In this case, now() will move 1% slower until it 
converges with the localtime(), which means that it takes 500 minutes 
before they are in sync.

Setting the time to a correct value before starting Erlang is the 
solution if this is not acceptable.

Try starting another node on the Zotonic, or restarting Erlang, and you 
should see similar times. Or try syncing the time before Erlang starts 
(ntpdate). You should also be able to see in files like 
/var/log/messages that the wall clock jumps.
> Anyway, logging here as the difference seems like a bug in Erlang.
>
> - Simon
Cheers,
/Patrik
>
>
>
>
> _______________________________________________
> erlang-bugs mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-bugs

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20130405/76d34a5a/attachment.html>


More information about the erlang-bugs mailing list