1

我尝试这样做以使新日期比当前系统时间早 90 秒:

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}}

有没有简单的方法可以做到这一点?

4

1 回答 1

5

你不能只在 erlang 中添加元组。您可以在元组中添加单个整数,但要操纵时间,您应该使用calendar模块(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}}
于 2013-03-08T12:30:02.430 回答