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