C++获取当前时间和计算程序运行时间的方法
获取当前时间:
#include <iostream>
#include <Windows.h> using namespace std; int main() {
SYSTEMTIME sys;
GetLocalTime(&sys);
cout<<sys.wYear<<"年";
cout<<sys.wMonth<<"月";
cout<<sys.wDay<<"日";
cout<<sys.wHour<<"时";
cout<<sys.wMinute<<"分";
cout<<sys.wSecond<<"秒";
cout<<sys.wMilliseconds<<"毫秒";
cout<<",星期"<<sys.wDayOfWeek<<endl;
return 0;
} 计算程序运行时间 方法一: #include<iostream.h>
#include<time.h>
void main()
{
   clock_t start,finish;
   double totaltime;
   start=clock();    …… //把你的程序代码插入到这里面    finish=clock();
   totaltime=(double)(finish-start) / CLOCKS_PER_SEC;  //CLOCKS_PER_SEC注意一下
   cout<<"\n此程序的运行时间为"<<totaltime<<"秒!"<<endl;
} 计算程序运行时间 方法二: #include <iostream>
#include <Windows.h> //关键
using namespace std;
int main() {
LONGLONG start, finish;
LONGLONG totalTime;
start = GetTickCount();
//需要测试运行时间的代码段放在这
finish = GetTickCount();
totalTime = finish - start;
cout<<"花费"<<totalTime<<"毫秒"<<endl;
return 0;
}

  

C++获取当前时间和计算程序运行时间的方法的更多相关文章

  1. VC++ 获取系统时间、程序运行时间(精确到秒,毫秒)的五种方法

    1.使用CTime类(获取系统当前时间,精确到秒) CString str; //获取系统时间 CTime tm; tm=CTime::GetCurrentTime();//获取系统日期 str=tm ...

  2. 【VS开发】VC++ 获取系统时间、程序运行时间(精确到秒,毫秒)的五种方法

    1.使用CTime类(获取系统当前时间,精确到秒) CString str; //获取系统时间 CTime tm; tm=CTime::GetCurrentTime();//获取系统日期 str=tm ...

  3. Java获取指定时间的毫秒值的方法

    有以下两种方法获取指定时间的毫秒值: 1.Calendar类 先由getInstance获取Calendar对象,然后用clear方法将时间重置为(1970.1.1 00:00:00),接下来用set ...

  4. c# 三种计算程序运行时间的方法

    三种计算c#程序运行时间的方法第一种:利用 System.DateTime.Now // example1: System.DateTime.Now method DateTime dt1 = Sys ...

  5. IOS 获取的时间显示为NAN 解决方法

    var regTime= item.BeginDate.replace(/\-/g, "/"); ------ item.BeginDate 我的日期年月日的    (/\-/g, ...

  6. PHP获取当前时间、时间戳的各种格式写法汇总[日期时间](转)

    今天写下PHP中,如何通过各种方法 获取当前系统时间.时间戳,并备注各种格式的含义,可灵活变通.1.获取当前时间方法date()很简单,这就是获取时间的方法,格式为:date($format, $ti ...

  7. 【转】PHP获取当前时间、时间戳的各种格式写法汇总[日期时间]

    今天写下php中,如何通过各种方法 获取当前系统时间.时间戳,并备注各种格式的含义,可灵活变通.1.获取当前时间方法date()很简单,这就是获取时间的方法,格式为:date($format, $ti ...

  8. java学习第13天( java获取当前时间,有关大数据的运算及精确数字运算,Date类)

    一 java获取当前时间 学习一个函数,得到当前时间的准确值 System.currectTimeMillis(). 可以得到以毫秒为单位的当前时间.它主要用于计算程序运行时间,long start= ...

  9. VC/MFC中计算程序运行时间

    转自原文VC/MFC中计算程序运行时间 说明,这四种方法也分别代表了类似的实现,在MFC中,所可以从哪些类集合去考虑. 方法一 利用GetTickCount函数(ms) CString str; lo ...

随机推荐

  1. 17.1.2.1 Advantages and Disadvantages of Statement-Based and Row-Based Replication

    17.1.2.1 Advantages and Disadvantages of Statement-Based and Row-Based Replication 基于语句和基于行复制的优点和缺点: ...

  2. android搭建环境错误 daemon not running. starting it now on port 5037 ADB server didn't ACK

    android搭建环境错误 daemon not running. starting it now on port 5037 ADB server didn't ACK ADB server didn ...

  3. QLinkedList和std::forward_list

    forward_list forward_list是C++11版本才有的.forward_list被实现为单链表,而list是一个双向链表,所以forward_list要比list高效一些.forwa ...

  4. js推断指定函数、变量是否存在的方法

    //推断是否存在指定函数 function isExitsFunction(funcName) { try { if (typeof (eval(funcName)) == "functio ...

  5. MapReduce的C#实现及单元测试(试验)

    MapReduce.cs类文件代码  MapReduce的执行方法 using System; using System.Collections.Generic; //using System.Lin ...

  6. windows cmd: 增强windows命令行

    1. 安装clink插件使得windows cmd.exe更好用 https://github.com/mridgers/clink/releases Overview: Clink combines ...

  7. 关于PagedDataSource分页属性与DataSet和DataTable详解

    Asp.net提供了三个功能强大的列表控件:DataGrid.DataList和Repeater控件,但其中只有DataGrid控件提供分页功能.相对DataGrid,DataList和Repeate ...

  8. week4_motion_of_ball_1(小球运动)——改进

    # Ball motion with an explicit timer import simplegui # Initialize globals width = 600 height = 600 ...

  9. BZOJ 1827: [Usaco2010 Mar]gather 奶牛大集会( dp + dfs )

    选取任意一个点为root , size[ x ] 表示以 x 为根的子树的奶牛数 , dp一次计算出size[ ] && 选 root 为集会地点的不方便程度 . 考虑集会地点由 x ...

  10. HTML5 总结-地理定位-6

    HTML5 地理定位 定位用户的位置 HTML5 Geolocation API 用于获得用户的地理位置. 鉴于该特性可能侵犯用户的隐私,除非用户同意,否则用户位置信息是不可用的. 浏览器支持 Int ...