我以为有一个Date的类,不像Java,C++没有这个类,可以使用C库time.h的函数来获取当前时间,或者调用DOS的date
方法一:
#include <iostream>
#include <ctime>
#include<string>
using namespace std;
int main ()
{
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
cout<<"Current local time and date:"<< asctime (timeinfo)<<endl;
system("pause");
return 0;
}
方法二:
#include<iostream>
#include<ctime>
#include<string>
using namespace std;
int main(){
time_t lltime;
time(lltime);
cout<<"the time is "<<ctime(lltime)<<endl;
system("pause");
return 0;
}
方法三:
include <ctime>
#include<string>
using namespace std;
#define CCT (+8)
int main ()
{
time_t rawtime;
struct tm * ptm;
time ( &rawtime );
ptm = gmtime ( &rawtime );
cout<<"Beijing (China):"<<(ptm->tm_hour+CCT)%24<<":"<<ptm->tm_min<<endl;
system("pause");
return 0;
}
方法四:
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(){
system("time");
system("pause");
return 0;
}
分享到:
相关推荐
C++获取当前时间精确到毫秒Ms
讲述C、C++如何获取系统时间的方法,以及详尽用法解释。
C++获取系统时间 很全面的哦 C++获取系统时间 很全面的哦
C++获取当前时间和计算程序运行时间的方法
This file contains a summary of what you will find in each of the files that make up your Example application.
25.如何在状态栏上显示当前时间?(Visual C++编程 源代码)25.如何在状态栏上显示当前时间?(Visual C++编程 源代码)25.如何在状态栏上显示当前时间?(Visual C++编程 源代码)25.如何在状态栏上显示当前时间?...
C++按年月日时分秒输出当前系统时间(压缩包包括已编译好的exe文件)
本文实例讲述了C++获取当前系统时间的方法。分享给大家供大家参考。具体如下: 方案— 优点:仅使用C标准库;缺点:只能精确到秒级 #include #include int main( void ) { time_t t = time(0); char tmp[64]; ...
用Visual C++编写的获取系统的当前时间
例如输入当前时间2006年12月20日19时17分59秒,计算后输出 时间是2006年12月20日19时18分00秒。 • 程序要求: • 程序应该可以运行:通过控制台输入数据,输出数据通过printf 给出; • 程序结构明了、逻辑清晰; ...
实例017——获取当前的日期、时间并格式化输出
使用C/C++函数获取当前系统时间并以当前系统时间为名称创建文档
VS2017 windows下 c++ 获取零点时间秒数。字符串转时间,然后获得秒数。转换准确,简单易用。
qt 获取北京时间 c++ 代码 类 主要是应用 qt库
C++中于获取当前时间的函数.doc
总结了常用的四种方法。包括: 方法一 利用 SYSTEMTIME 方法二 利用 GetTickCount()函数 方法三 使用clock()函数 方法四 获取高精度时间差 个人感觉还是很清晰明了的。希望对大家有用。
C/C++如何获取当前系统时间的实例详解 C库中与系统时间相关的函数定义在头文件中, C++定义在头文件中。 一、time(time_t*)函数 函数定义如下: time_t time (time_t* timer); 获取系统当前日历时间 UTC 1970-01...
windows下 c++ VS2017读取系统时间生成txt文件名 c++ VS2017读取系统时间生成txt文件名 c++ VS2017读取系统时间生成txt文件名 c++ VS2017读取系统时间生成txt文件名
vc6.0环境下基于对话框的获取当前时间日期并格式化输出,测试通过
获取系统当前时间的代码!最简单的代码,是需要的人看起来一目了然!能很好的截取代码用到自己需要的地方并且能使很快达到要求!