本文摘自PHP中文网,作者coldplay.xixi,侵删。
c++获取系统时间的方法:1、使用系统函数,并且可以修改系统时间;2、获取系统时间,代码为【time_t now_time=time(NULL)】;3、使用windows API ,精确到毫秒级。
c++获取系统时间的方法:
1、使用系统函数,并且可以修改系统时间
1 2 3 4 5 6 7 8 | # include <stdlib.h>
using namespace std;
void main()
{
system( "time" );
}
|
备注:获取的为 小时:分钟:秒 信息
2、获取系统时间(秒级),可以换算为年月日星期时分秒
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | # include <iostream>
# include <time.h>
using namespace std;
void main()
{
time_t now_time=time(NULL);
tm* t_tm = localtime(&now_time);
printf( "local time is : %s\n" , asctime(t_tm));
time_t mk_time = mktime (t_tm);
struct tm deadline_tm;
deadline_tm.tm_sec=0;
deadline_tm.tm_min=10;
deadline_tm.tm_hour=13;
deadline_tm.tm_isdst=0;
deadline_tm.tm_mday=31;
deadline_tm.tm_mon=2;
}
|
3、使用windows API ,精确到毫秒级
1 2 3 4 5 6 7 8 9 | # include <windows.h>
# include <stdio.h>
using namespace std;
void main()
{
SYSTEMTIME sys;
GetLocalTime( &sys );
printf( "%4d/%02d/%02d %02d:%02d:%02d.%03d 星期%1d\n" ,sys.wYear,sys.wMonth,sys.wDay,sys.wHour,sys.wMinute, sys.wSecond,sys.wMilliseconds,sys.wDayOfWeek);
|
相关学习推荐:C视频教程
以上就是c++如何获取系统时间?的详细内容!
相关阅读 >>
microsoft visual C++ 怎么使用?
dev C++怎么用
C++源程序文件的扩展名是什么
常见的C++中const常量用法分析讲解
C++万能头文件是什么?
C++是什么意思
技术解答面向对象的初步认识(C++ 类)
C++笔试题之实现简单记录错误功能
C++ 图解层序遍历和逐层打印智能指针建造的二叉树
C++学习基础知识--this指针、静态成员、常量成员函数
更多相关阅读请进入《C++》频道 >>
转载请注明出处:木庄网络博客 » c++如何获取系统时间?