修改系统时间

来源:互联网 发布:上海企业网络推广平台 编辑:程序博客网 时间:2024/06/05 20:06
#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();
}