获取(设置)系统时间

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值