字符串与时间戳的转换
日期字符串转换为时间戳
思路:
- 将日期字符串转换为时间结构体
- 将时间结构体转换为对应的时间戳(
time_t
类型,其实是long
类型的别名)
日期字符串转换为时间戳
1 | time_t convertDateToTimestamp(const string &date) |
日期时间字符串转换为时间戳
思路:
- 将日期字符串转换为时间结构体
- 将时间结构体转换为对应的时间戳(
time_t
类型,其实是long
类型的别名)
日期时间字符串转换为时间戳
1 | // 日期时间字符串转换为对应的时间戳 |
时间戳转换为日期字符串
思路:
- 将时间戳转换为
struct tm
类型的时间:使用localtime_r
函数或者localtime
函数 - 然后将
struct tm
类型的时间按照给定格式化串格式化为字符串:使用strftime
函数
时间戳转换为日期字符串
1 | // 时间戳转换为日期 |
时间戳转换为日期时间字符串
思路:
- 将时间戳转换为
struct tm
类型的时间:使用localtime_r
函数或者localtime
函数 - 然后将
struct tm
类型的时间按照给定格式化串格式化为字符串:使用strftime
函数
时间戳转换为日期时间字符串
1 | // 时间戳转换为日期时间 |