문제

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