• API
• FAQ
• Tools
• Archive
daily pastebin goal
15%
SHARE
TWEET

# Untitled

a guest Aug 14th, 2018 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. Date = {{2018,8,14},{13,10,25}}.
2. DateInSeconds = calendar:datetime_to_gregorian_seconds(Date).  % 63701471425
3. NewDateInSeconds = DateInSeconds + 10.                         % 63701471435
4. calendar:gregorian_seconds_to_datetime(NewDateInSeconds).      % {{2018,8,14},{13,10,35}}
5.
6. Date = {{2018,8,14},{13,10,25}}.
7. DateInSeconds = calendar:datetime_to_gregorian_seconds(Date).  % 63701471425
8. NewDateInSeconds = DateInSeconds + (10 * 60 * 60).             % 63701507425 (10 hours)
9. calendar:gregorian_seconds_to_datetime(NewDateInSeconds).      % {{2018,8,14},{23,10,25}}
10.
11. -type datetime() :: {{non_neg_integer(), pos_integer(), pos_integer()},
12.                      {non_neg_integer(), non_neg_integer(), non_neg_integer()}}.
13. -type timespan() :: {integer(), integer(), integer()}.
14.
15. -spec add_time_to_datetime(datetime(), timespan()) -> datetime().
16. add_time_to_datetime(DateTime, {Hour, Min, Sec}) ->
17.     DateInSeconds = calendar:datetime_to_gregorian_seconds(Date),
18.     NewDateInSeconds = DateInSeconds + (Hour * 60 * 60) + (Min * 60) + Sec,
19.     calendar:gregorian_seconds_to_datetime(NewDateInSeconds).
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top