修改系统时间

#include <ctime>
#include<Windows.h>
#include <iostream>
using namespace std;

int main()
{
SYSTEMTIME curr_st;
GetLocalTime(&curr_st);
//修改系统时间
unsigned short a=59;
curr_st.wYear=2006;
curr_st.wMonth=12;
curr_st.wDay=1;
curr_st.wHour=3;
curr_st.wMinute=a;
curr_st.wSecond=59;
curr_st.wMilliseconds=0;

SetLocalTime(&curr_st);

Sleep(1000);
//
struct tm *local,*ptr; //定义tm结构指针存储时间信息
time_t t; //时间结构或者对象
t=time(NULL); //获取当前系统的日历时间
//通过time()函数来获得日历时间(Calendar Time),
//其原型为:time_t time(time_t * timer);
local=localtime(&t);//localtime()函数是将日历时间转化为本地时间
//printf("Local hour is: %d/n",local->tm_hour);//输出tm结构体的时间成员
//printf("UTC hour is: %d/n",local->tm_hour);
//local=gmtime(&t);
//gmtime()函数是将日历时间转化为世界标准时间(即格林尼治时间),
//并返回一个tm结构体来保存这个时间
ptr=gmtime(&t);//将日历时间转化为世界标准时间
//printf("The UTC time is %s/n",asctime(ptr)); //格式化输出世界标准时间
printf("The local time is %s",ctime(&t));//输出本地时间
/*asctime()函数(参数为tm结构指针)和ctime()函数(参数为time_t结构)将时间以固定的格式显示出来,两者的返回值都是char*型的字符串。返回的时间格式为:星期几 月份 日期 时:分:秒 年/n/0 */
getchar();
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值