MFC
1 CTime t = CTime::GetCurrentTime();
2 t.GetLocalTm(struct tm*);
SDK
The SetLocalTime function sets the current local time and date.
1 BOOL SetLocalTime(
2 CONST SYSTEMTIME *lpSystemTime // local time
3 );
The SetSystemTime function sets the current system time and date. The system time is expressed in Coordinated Universal Time (UTC).
1 in Coordinated Universal Time (UTC).
2 BOOL SetSystemTime(
3 CONST SYSTEMTIME *lpSystemTime // system time
4 );
CRT
01 #include <stdio.h>
02 #include <string.h>
03 #include <time.h>
04
05 void main()
06 {
07 struct tm *newtime;
08 char am_pm[] = "AM";
09 time_t long_time;
10
11 time( &long_time ); /* Get time as long integer. */
12 newtime = localtime( &long_time ); /* Convert to local time. */
13 if( newtime->tm_hour > 12 ) /* Set up extension. */
14 strcpy( am_pm, "PM" );
15 if( newtime->tm_hour > 12 ) /* Convert from 24-hour */
16 newtime->tm_hour -= 12; /* to 12-hour clock. */
17 if( newtime->tm_hour == 0 ) /*Set hour to 12 if midnight. */
18 newtime->tm_hour = 12;
19
20 printf( "%.19s %s/n", asctime( newtime ), am_pm );
21 }
参考:http://www.graphics.net.cn/bbs/vc/0019/006.asp
获取(设置)系统时间
最新推荐文章于 2021-07-20 16:01:39 发布