Time related functions 更多...
类 | |
struct | DateTime |
A type representing the combination of date and time. 更多... | |
函数 | |
double | TimeCounting () |
Precisely and cross-platform time counting function. | |
bool | IsLeapYear (const int yr) |
Check the given year is a leap year or not. 更多... | |
string | ConvertToString (const time_t date, bool utc_time=true) |
Convert date time to string as the format of "YYYY-MM-DD" 更多... | |
string | ConvertToString2 (const time_t date, bool utc_time=true) |
Convert date time to string as the format of "YYYY-MM-DD HH" 更多... | |
string | ConvertToString3 (const time_t date, bool utc_time=true) |
Convert date time to string as the format of "YYYY_MM_DD_HHMMSS" 更多... | |
time_t | ConvertToTime (const string &str_date, string const &format, bool include_hour, bool utc_time=true) |
Convert string to date time, string format could be %4d%2d%2d or d-d-d 更多... | |
time_t | ConvertYMDToTime (int &year, int &month, int &day, bool utc_time=true) |
Convert integer year, month, and day to date time 更多... | |
int | GetDateInfoFromTimet (time_t t, int *year, int *month, int *day, bool utc_time=true) |
Get date information from time_t variable 更多... | |
void | LocalTime (time_t date, struct tm *t) |
Get local time 更多... | |
void | UTCTime (time_t date, struct tm *t) |
Get UTC:+00:00 time 更多... | |
void | GetDateTime (time_t date, struct tm *t, bool utc_time=true) |
Get UTC:+00:00 time 更多... | |
int | GetYear (time_t date, bool utc_time=true) |
Get the year 更多... | |
int | GetMonth (time_t date, bool utc_time=true) |
Get the month 更多... | |
int | GetDay (time_t date, bool utc_time=true) |
Get the day 更多... | |
int | DayOfYear (time_t date, bool utc_time=true) |
Get the day of one year, [1, 366] | |
int | DayOfYear (int year, int month, int day) |
Get the day of one year, [1, 366] | |
int | JulianDay (time_t date, bool utc_time=true) |
Get the Julian day from time_t date | |
int | JulianDay (int year, int month, int day) |
Get the Julian day of one day from year, month, and day. 更多... | |
Time related functions
string ccgl::utils_time::ConvertToString | ( | const time_t | date, |
bool | utc_time = true |
||
) |
Convert date time to string as the format of "YYYY-MM-DD"
[in] | date | time_t data type |
[in] | utc_time | By default, the input date is under UTC+00:00 timezone. |
string ccgl::utils_time::ConvertToString2 | ( | const time_t | date, |
bool | utc_time = true |
||
) |
Convert date time to string as the format of "YYYY-MM-DD HH"
[in] | date | time_t data type |
[in] | utc_time | By default, the input date is under UTC+00:00 timezone. |
string ccgl::utils_time::ConvertToString3 | ( | const time_t | date, |
bool | utc_time = true |
||
) |
Convert date time to string as the format of "YYYY_MM_DD_HHMMSS"
[in] | date | time_t data type |
[in] | utc_time | By default, the input date is under UTC+00:00 timezone. |
time_t ccgl::utils_time::ConvertToTime | ( | const string & | str_date, |
string const & | format, | ||
bool | include_hour, | ||
bool | utc_time = true |
||
) |
Convert string to date time, string format could be %4d%2d%2d or d-d-d
Example:
[in] | str_date | string date |
[in] | format | string format |
[in] | include_hour | bool Include Hour? |
[in] | utc_time | By default, the input date is under UTC+00:00 timezone. |
time_t ccgl::utils_time::ConvertYMDToTime | ( | int & | year, |
int & | month, | ||
int & | day, | ||
bool | utc_time = true |
||
) |
Convert integer year, month, and day to date time
[in] | year | year number from 1970 |
[in] | month | month range from 1 to 12 |
[in] | day | day range from 1 to 31 |
[in] | utc_time | By default, the input date is under UTC+00:00 timezone. |
int ccgl::utils_time::GetDateInfoFromTimet | ( | time_t | t, |
int * | year, | ||
int * | month, | ||
int * | day, | ||
bool | utc_time = true |
||
) |
Get date information from time_t variable
[in] | t | time_t date |
[out] | year,month,day | int value |
[in] | utc_time | By default, the input date is under UTC+00:00 timezone. |
void ccgl::utils_time::GetDateTime | ( | time_t | date, |
struct tm * | t, | ||
bool | utc_time = true |
||
) |
Get UTC:+00:00 time
[in] | date | time_t date |
[out] | t | tm struct date |
[in] | utc_time | By default, the input date is under UTC+00:00 timezone. |
int ccgl::utils_time::GetDay | ( | time_t | date, |
bool | utc_time = true |
||
) |
Get the day
int ccgl::utils_time::GetMonth | ( | time_t | date, |
bool | utc_time = true |
||
) |
Get the month
int ccgl::utils_time::GetYear | ( | time_t | date, |
bool | utc_time = true |
||
) |
Get the year
bool ccgl::utils_time::IsLeapYear | ( | const int | yr | ) |
Check the given year is a leap year or not.
divisible by 4, not if divisible by 100, but true if divisible by 400
int ccgl::utils_time::JulianDay | ( | int | year, |
int | month, | ||
int | day | ||
) |
Get the Julian day of one day from year, month, and day.
Algorithm adopted from boost::date_time::gregorian_calendar_base::day_number.
void ccgl::utils_time::LocalTime | ( | time_t | date, |
struct tm * | t | ||
) |
Get local time
[in] | date | time_t date |
[out] | t | tm struct date |
void ccgl::utils_time::UTCTime | ( | time_t | date, |
struct tm * | t | ||
) |
Get UTC:+00:00 time
[in] | date | time_t date |
[out] | t | tm struct date |