e and time expressed in UTC-based
/// time. UTC base time is midnight, October 15, 1582.
/// Resolution is 100 nanoseconds.
bool operator == (const DateTime& dateTime) const;
bool operator != (const DateTime& dateTime) const;
bool operator < (const DateTime& dateTime) const;
bool operator <= (const DateTime& dateTime) const;
bool operator > (const DateTime& dateTime) const;
bool operator >= (const DateTime& dateTime) const;
DateTime operator + (const Timespan& span) const;
DateTime operator - (const Timespan& span) const;
Timespan operator - (const DateTime& dateTime) const;
DateTime& operator += (const Timespan& span);
DateTime& operator -= (const Timespan& span);
void makeUTC(int tzd);
/// Converts a local time into UTC, by applying the given time zone
differential.
void makeLocal(int tzd);
/// Converts a UTC time into a local time, by applying the given time
zone differential.
static bool isLeapYear(int year);
/// Returns true if the given year is a leap year;
/// false otherwise.
static int daysOfMonth(int year, int month);
/// Returns the number of days in the given month
/// and year. Month is from 1 to 12.
static bool isValid(int year, int month, int day, int hour = 0, int minute =
0, int second = 0, int millisecond = 0, int microsecond = 0);
/// Checks if the given date and time is valid
/// (all arguments are within a proper range).
///
/// Returns true if all arguments are valid, false otherwise.
protected:
// ...
private:
// ...
Timestamp::UtcTimeva l _utcTime;
short _year;
short _month;
short _day;
short _hour;
short _minute;
short _second;
short _millisecond;
short _microsecond;
};
Poco::DateTime是基于格里高利历(Gregorian calendar)(就是公历啦)设计的。它除了可以用来保存日历时间外,还可以被用于日期计算。如果只是为了日历时间的存储,Timestamp类更加适合。在DateTime的内部,DateTime类用两种格式维护了日期和时间。第一种是UTC日历时间。第二种是用年、月、日、时、分、秒、微秒、毫秒。为了进行内部时间日期之间的换算,DateTime使用了儒略日(Julian day)历法。
格里高利历(Gregorian calendar)
格里高利历就是我们通常讲的公历。它以耶稣的诞生为初始年份,也就是公元0001年。格里高利历以日为基本单位,1年有365或366天,分成12个月,每个月时长不等。由于不同国家采用格里高利历时间不同(德国1582, 英国1752),所以格里高利历日期和旧式的日期有差别,即使是用来表示历史上相同的一件事。一个耶稣像,^_^。
_ xxxx _
/_;-.__ / _\ _.-;_\
`-._`'`_/'`.-'
`\ /`
| /
/-.(
\_._\
\ \`;
> |/
/ //
|//
\(\
儒略日和儒略日日期
儒略日的起点订在公元前4713年(天文学上记为 -4712年)1月1日格林威治时间平午(世界时12:00),即JD 0指定为UT时间B.C.4713年1月1日12:00到UC时间B.C.4713年1月2日12:00的24小时。注意这一天是礼拜一。每一天赋予了一个唯一的数字,顺数而下,如:1996年1月1日12:00:00的儒略日是2450084。这个日期是考虑了太阳、月亮的轨道运行周期,以及当时收税的间隔而订出来的。Joseph Scliger定义儒略周期为7980年,是因28、19、15的最小公倍数为28×19×15=7980。
日期的注意事项:
1. 0是一个合法数字(根据ISO 8691和天文年编号)
2. 0年是一个闰年。
3. 负数是不支持的。比如说公元前1年。
4. 格里高利历同历史上的日期可能不同,由于它们采用的日历方式不同。
5. 最好只是用DateTime用来计算当前的时间。对于历史上的或者天文日历的时间计算,还是使用其他的特定软件。
构造DateTime:
1. 可以从一个已有的DateTime构造
2. 当前的时间和日期
3. 一个Timestamp对象
4. 用年、月、日、时、分、秒、微秒、毫秒构造
5. 使用一个儒略日日期构造(用double形式保存)
成员函数:
1. int year() const
返回年
2. int month() const
返回月(1-12)
3. int week(int firstDayOfWeek = DateTime::MONDAY) const
返回所在的周,根据ISO 8601标准(第一周是1月4日所在的周),一周的第一天是礼拜一或者礼拜天。
4. int day() const
返回月中的所在天(1 - 31)
5. int dayOfWeek() const
返回周中的所在天 0为周日,1为周一,.....
6. int dayOfYear() con