獲取系統時間的兩種方法

void gettime()
{
	time_t rawtime;
	struct tm* ptminfo;
	time(&rawtime);
	ptminfo = localtime(&rawtime);
	printf("current: %02d-%02d-%02d %02d:%02d:%02d\n",
		ptminfo->tm_year + 1900, ptminfo->tm_mon + 1, ptminfo->tm_mday,
		ptminfo->tm_hour, ptminfo->tm_min, ptminfo->tm_sec);
}

void GetComputerTime()
{
	LPSYSTEMTIME p_st = (LPSYSTEMTIME)malloc(sizeof(SYSTEMTIME));
	GetLocalTime(p_st);
	cout << "現在時間:" << p_st->wYear << "/" << p_st->wMonth << "/" << p_st->wDay << " "
		<< p_st->wHour << ":" << p_st->wMinute << ":" << p_st->wSecond << endl;
	//printf("%d:%d:%d\n", p_st->wHour, p_st->wMinute, p_st->wSecond);
	free(p_st);
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章