900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > VC字符串与时间戳相互转换

VC字符串与时间戳相互转换

时间:2020-05-23 23:00:29

相关推荐

VC字符串与时间戳相互转换

原理及代码都很简单(比网上那些用time结构体转来转去方便多了),就不讲了,直接上码:

#include <Windows.h>#include <atlstr.h>#include <ATLComTime.h>#include <atltime.h>int main(){//字符串转时间戳CString strTime = "-07-18 19:30:22";COleDateTime oletime;__int64 instatime = 0;if (oletime.ParseDateTime(strTime)){CTime ctime(oletime.GetYear(), oletime.GetMonth(), oletime.GetDay(), oletime.GetHour(), oletime.GetMinute(), oletime.GetSecond());instatime = ctime.GetTime();printf("时间戳:%ld\n",instatime);}//时间戳转字符串COleDateTime oletime2(instatime);CString strDate = oletime2.Format(L"%Y-%m-%d %H:%M:%S");printf("时间:%S\n", strDate.GetBuffer());system("pause");return 0;}

程序输出:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。