shijiang1130 发表于 2016-05-23 09:33

erlang好用日期模块

https://github.com/choptastic/qdate

shijiang1130 发表于 2016-05-23 09:33

Date Arithmetic from "now"

There are 7 other arithmetic functions that take a single argument, and these do arithmetic from "now." For example, add_years(4) is a shortcut for add_years(4, os:timestamp()).

add_seconds(Seconds)
add_minutes(Minutes)
add_hours(Hours)
add_days(Days)
add_weeks(Weeks)
add_months(Months)
add_years(Years)
Date and Time Ranges

qdate provides a number of range functions that give applicable dates/times within a start and end time. For example, "All days from 2015-01-01 to today", "every 3rd month from 2000-01-01 to 2009-12-31", or "every 15 minutes from midnight to 11:59pm on 2015-04-15".

The functions are as follows:

range_seconds(Interval, Start, End)
range_minutes(Interval, Start, End)
range_hours(Interval, Start, End)
range_days(Interval, Start, End)
range_weeks(Interval, Start, End)
range_months(Interval, Start, End)
range_years(Interval, Start, End)
Where Interval is the number of seconds/days/years/etc.

So for example:

%% Get every 15th minute from "2015-04-15 12:00am to 2015-04-15 11:59am"
> qdate:range_minutes(15, "2015-04-15 12:00am", "2015-04-15 11:59am").
[1429056000,1429056900,1429057800,1429058700,1429059600,
1429060500,1429061400,1429062300,1429063200,1429064100,
1429065000,1429065900,1429066800,1429067700,1429068600,
1429069500,1429070400,1429071300,1429072200,1429073100,
1429074000,1429074900,1429075800,1429076700,1429077600,
1429078500,1429079400,1429080300,1429081200|...]

%% Get every day of April, 2014
> qdate:range_days(1, "2014-04-01", "2014-04-30").
[1396310400,1396396800,1396483200,1396569600,1396656000,
1396742400,1396828800,1396915200,1397001600,1397088000,
1397174400,1397260800,1397347200,1397433600,1397520000,
1397606400,1397692800,1397779200,1397865600,1397952000,
1398038400,1398124800,1398211200,1398297600,1398384000,
1398470400,1398556800,1398643200,1398729600|...]

patagonia2 发表于 2016-05-23 13:15

学了Er之后,我就想Er 真的很好!
为什么?
Er对初学者很友好,好多非常好用的一些模块
{:yxh93:}
页: [1]
查看完整版本: erlang好用日期模块