Date and time utilities

来自cppreference.com
< cpp


 
 
实用工具库
类型的支持 (basic types, RTTI, type traits)
动态内存管理
错误处理
程序实用工具
可变参数函数
日期和时间
函数对象
initializer_list(C++11)
bitset
hash(C++11)
关系运算符
原文:
Relational operators
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
rel_ops::operator!=
rel_ops::operator>
rel_ops::operator<=
rel_ops::operator>=
双和元组
原文:
Pairs and tuples
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
pair
tuple(C++11)
piecewise_construct_t(C++11)
piecewise_construct(C++11)
掉期,远期和移动
原文:
Swap, forward and move
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
swap
forward(C++11)
move(C++11)
move_if_noexcept(C++11)
declval(C++11)
 
日期和时间工具
 
C + +支持两种类型的操作时间:
原文:
C++ includes support for two types of time manipulation:
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • chrono图书馆,灵活的收集跟踪时间的类型,不同的精确度(例如std::chrono::time_point
    原文:
    The chrono library, a flexible collection of types that track time with varying degrees of precision (e.g. std::chrono::time_point).
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
  • C-风格的日期和时间库(例如std::time
    原文:
    C-style date and time library (e.g. std::time)
    这段文字是通过 Google Translate 自动翻译生成的。
    您可以帮助我们检查、纠正翻译中的错误。详情请点击这里

目录

[编辑] NJ库

chrono库定义了三种主要的类型(持续时间,时钟和时间点),以及实用的功能和常见的类型定义.
原文:
The chrono library defines three main types (durations, clocks, and time points) as well as utility functions and common typedefs.
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里

[编辑] 持续时间

持续时间的时间跨度,定义为一定数量的蜱一段时间的单位。例如,“42秒”可以表示的组成的持续时间中的42的一个1秒的时间单元蜱.
原文:
A duration consists of a span of time, defined as some number of ticks of some time unit. For example, "42 seconds" could be represented by a duration consisting of 42 ticks of a 1-second time unit.
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
在头文件 <chrono> 中定义
定义于 std::chrono 名字空间
(C++11)
一个时间间隔
原文:
a time interval
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里

(类模板) [edit]

[编辑] 时钟

一个时钟由一个起点(或时代)和时钟速率。例如,时钟可以有一个具有划时代意义的1970年1月1日,并勾选每一秒。 C + +定义了三种时钟方式:
原文:
A clock consists of a starting point (or epoch) and a tick rate. For example, a clock may have an epoch of January 1, 1970 and tick every second. C++ defines three clock types:
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
在头文件 <chrono> 中定义
定义于 std::chrono 名字空间
(C++11)
从系统获取的实时时钟
原文:
wall clock time from the system-wide realtime clock
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里

(类) [edit]
(C++11)
单调时钟将永远不会被调整
原文:
monotonic clock that will never be adjusted
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里

(类) [edit]
的时钟用最短的剔期
原文:
the clock with the shortest tick period available
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里

(类) [edit]

[编辑] 时间点

时间点是一个持续的时间已经过去了时代的特定的时钟.
原文:
A time point is a duration of time that has passed since the epoch of specific clock.
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里
在头文件 <chrono> 中定义
定义于 std::chrono 名字空间
(C++11)
a point in time
(类模板) [edit]

[编辑] C-风格的日期和时间库

本发明还提供C风格的日期和时间的函数,如std::time_tstd::difftime,和CLOCKS_PER_SEC.
原文:
Also provided are the C-style date and time functions, such as std::time_t, std::difftime, and CLOCKS_PER_SEC.
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里

[编辑] 示例

这个例子显示一个函数调用的执行时间信息
原文:
This example displays information about the execution time of a function call:
这段文字是通过 Google Translate 自动翻译生成的。
您可以帮助我们检查、纠正翻译中的错误。详情请点击这里

#include <iostream>
#include <chrono>
#include <ctime>
 
int fibonacci(int n)
{
    if (n < 3) return 1;
    return fibonacci(n-1) + fibonacci(n-2);
}
 
int main()
{
    std::chrono::time_point<std::chrono::system_clock> start, end;
    start = std::chrono::system_clock::now();
    int result = fibonacci(42);
    end = std::chrono::system_clock::now();
 
    int elapsed_seconds = std::chrono::duration_cast<std::chrono::seconds>
                             (end-start).count();
    std::time_t end_time = std::chrono::system_clock::to_time_t(end);
 
    std::cout << "finished computation at " << std::ctime(&end_time)
              << "elapsed time: " << elapsed_seconds << "s\n";
}

Possible output:

finished computation at Sat Jun 16 20:42:57 2012
elapsed time: 3s