首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VC >

Vc.Net获取当前计算机时间?解决办法

2012-03-06 
Vc.Net获取当前计算机时间?麻烦给个代码,另外要不要引用头文件捏![解决办法]DateTime::Now[解决办法]DateT

Vc.Net获取当前计算机时间?
麻烦给个代码,另外要不要引用头文件捏!

[解决办法]
DateTime::Now
[解决办法]
DateTime dt = DateTime::Now;
labTimer->Text = dt.ToString(L"yyyy-MM-dd HH:mm:ss");
[解决办法]
非托管的可以用
#include <windows.h>

// SetFileToCurrentTime - sets last write time to current system time
// Return value - TRUE if successful, FALSE otherwise
// hFile - must be a valid file handle

BOOL SetFileToCurrentTime(HANDLE hFile)
{
FILETIME ft;
SYSTEMTIME st;
BOOL f;

GetSystemTime(&st); // gets current time
SystemTimeToFileTime(&st, &ft); // converts to file time format
f = SetFileTime(hFile, // sets last-write time for file
(LPFILETIME) NULL, (LPFILETIME) NULL, &ft);

return f;
}

热点排行