سؤال

I tried doing this to make a new date 90 seconds ahead of the current system time:

12> {{00,00,00},{00,01,30}}+erlang:localtime().
** exception error: an error occurred when evaluating an arithmetic expression
     in operator  +/2
        called as {{0,0,0},{0,1,30}} + {{2013,3,8},{6,3,33}}

Are there any easy methods for doing this?

هل كانت مفيدة؟

المحلول

You can't just add tuples in erlang. You could add the individual integers inside the tuples but to manipulate time, you should use the calendar module (docs):

1> Added = calendar:datetime_to_gregorian_seconds(calendar:local_time()) + 90.
63529954043
2> calendar:gregorian_seconds_to_datetime(Added).
{{2013,3,8},{9,27,23}}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top