将 UTC 时间转换为 CString 格式
Convert UTC time into CString format
我需要获取 Unix UTC 格式的当前系统时间并将其转换为 CString。我正在尝试这样做
CTime time = CTime::GetCurrentTime();
CString string = time.FormatGmt(L"%d");
代码是 运行,但是 'string' 变量包含一个错误的值,它应该包含类似“1011173512”的内容,即自 1970 年以来的秒数。有人知道为什么吗???
函数 CTime::FormatGmt
使用与 strftime
相同的格式规则。
特别是,%d
表示 "Day of month as decimal number (01 – 31)"。
我怀疑您想要一个 time_t
或类似的对象。我建议你想要 GetTime
方法,其中 returns a _time64_t
.
所以:
CTime time = CTime::GetCurrentTime();
CString string; string.Format(L"%lld", time.GetTime());
我需要获取 Unix UTC 格式的当前系统时间并将其转换为 CString。我正在尝试这样做
CTime time = CTime::GetCurrentTime();
CString string = time.FormatGmt(L"%d");
代码是 运行,但是 'string' 变量包含一个错误的值,它应该包含类似“1011173512”的内容,即自 1970 年以来的秒数。有人知道为什么吗???
函数 CTime::FormatGmt
使用与 strftime
相同的格式规则。
特别是,%d
表示 "Day of month as decimal number (01 – 31)"。
我怀疑您想要一个 time_t
或类似的对象。我建议你想要 GetTime
方法,其中 returns a _time64_t
.
所以:
CTime time = CTime::GetCurrentTime();
CString string; string.Format(L"%lld", time.GetTime());