C转换char[]为时间戳;
C convert char[] to timestamp;
我有char date[] =" 2011-04-01";它如何转换为时间戳在C或c++ ?
警告:strptime是posix函数(在操作系统"Windows"平台上可能无法通过time.h获得)
#include <time.h>
struct tm time;
strptime("2011-04-01", "%Y-%m-%d", &time);
time_t loctime = mktime(&time); // timestamp in current timezone
time_t gmttime = timegm(&time); // timestamp in GMT
试试这个:
char date[] = "2011-04-01";
date[4] = date[7] = ' ';
struct tm tmdate = {0};
tmdate.tm_year = atoi(&date[0]) - 1900;
tmdate.tm_mon = atoi(&date[5]) - 1;
tmdate.tm_mday = atoi(&date[8]);
time_t t = mktime( &tmdate );
相关文章:
- 将 unix 时间戳转换为人类可读的日期
- 使用 C++将时间戳转换为格式化的日期时间
- 如何将 time-uuid(存储在 boost uuid 中)转换为时间戳/自纪元以来的时间?
- 将日期字符串转换为 unix 时间戳
- 将带有参考时间的时间戳转换为格式化时间
- 如何将纳米第二个时期时间戳转换为可读格式
- 使用 std::chrono / date::gps_clock 将双 GPS 时间戳转换为 UTC/tai
- 将时间戳转换为纳秒 (Qt)
- C 将字符串时间戳转换为STD :: Chrono :: System_Clock :: Time_point
- 如何将WSTRING中的Unix时间戳转换为char数组中格式的日期
- 如何将 UTC 时间戳转换为本地时间,即整点后的几秒钟
- 时间戳转换错误
- 使用 std::chrono 将 32 位 unix 时间戳转换为 std::string
- C 将没有时区域区域区域的Postgres时间戳转换为Time_T
- 如何将负时间戳转换为字符串.C++
- C++ Boost将UNIX时间戳转换为MySQL兼容的DATETIME字符串
- 如何将时间戳t转换为实时
- 将unix时间戳(s)转换为c++中的星期几
- 64位Unix时间戳转换
- Unix时间戳转换在JS和QTDatetime的区别