[erlang-questions] Current time in milliseconds

Tony Rogvall tony@REDACTED
Sun Dec 7 11:04:00 CET 2008

erlang:now() returns number of micro seconds since Jan 1970 but
it's encoded into a 3-tuple.

MegaSes is seconds*100000.

When the first Erlang system was built we had no bignums so we had to
encode the data using 28 bit integers. That is the reason why we
had to use the Mega seconds part. This is of course not the reason why
we still keep the erlang:now function as it has always been ;-)

To convert a now "stamp" into micro seconds you could do:

now_us({MegaSecs,Secs,MicroSecs}) ->
	(MegaSecs*1000000 + Secs)*1000000 + MicroSecs.


On 6 dec 2008, at 15.46, Ahmed Ali wrote:

> Hi,
> I found now() function which returns {MegaSecs, Secs, Microsecs}. Now
> the next question is what is MegaSecs? and is Microsecs value is the
> number of microseconds in this second or is it also since zero hour
> (00:00 GMT, January 1, 1970)?
> Best regards,
> Ahmed
> On Sat, Dec 6, 2008 at 6:31 PM, Ahmed Ali <ahmed.nawras@REDACTED>  
> wrote:
>> Hi List,
>> I'd like to get the current time in milliseconds. I've been looking
>> around but couldn't find a way to do this in Erlang. Can anyone  
>> please
>> help?
>> Best regards,
>> Ahmed
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions

More information about the erlang-questions mailing list