Пространства имён
Варианты
Действия

Date and time utilities

Материал из cppreference.com
< cpp

C + + включает в себя поддержку двух типов время манипуляций
Original:
C++ includes support for two types of time manipulation:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • chrono библиотеки, гибкий коллекцию типов, которые отслеживают время с различной степенью точности (например, std::chrono::time_point).
    Original:
    The chrono library, a flexible collection of types that track time with varying degrees of precision (e.g. std::chrono::time_point).
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • C-стиле дату и время библиотеки (например, std::time)
    Original:
    C-style date and time library (e.g. std::time)
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

Содержание

[править] NJ библиотеки

Библиотека chrono определяет три основных типа (продолжительность, часы и моменты времени), а также вспомогательные функции и общие определения типов.
Original:
The chrono library defines three main types (durations, clocks, and time points) as well as utility functions and common typedefs.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[править] Продолжительность

Продолжительность состоит из промежуток времени, определяемый как некоторое количество тактов некоторых единицу времени. Например, "42 секунд" может быть представлена ​​продолжительность состоящий из 42 клещей 1-секундный единицу времени.
Original:
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.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Определено в файле <chrono>
Defined in namespace std::chrono
(C++11)
интервал времени
Original:
a time interval
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(шаблон класса) [edit]

[править] Часы

Часы состоят из начальной точки (или эпохой) и галочка скорости. Например, часы могут иметь эпохи состоянию на 1 января 1970 года и отметьте каждую секунду. C + + определяет три типа часов
Original:
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:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Определено в файле <chrono>
Defined in namespace std::chrono
Настенные часы время от общесистемного часов реального времени
Original:
wall clock time from the system-wide realtime clock
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(класс) [edit]
монотонная часы, которые никогда не будут скорректированы
Original:
monotonic clock that will never be adjusted
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(класс) [edit]
Часы с самым коротким периодом тик в наличии
Original:
the clock with the shortest tick period available
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(класс) [edit]

[править] Время точка

Момент времени является продолжительность времени, которое прошло с начала эпохи конкретные часы.
Original:
A time point is a duration of time that has passed since the epoch of specific clock.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Определено в файле <chrono>
Defined in namespace std::chrono
a point in time
(шаблон класса) [edit]

[править] C-стиле дату и время библиотека

Также предусмотрены C-стиле функции даты и времени, таких как std::time_t, std::difftime, и CLOCKS_PER_SEC.
Original:
Also provided are the C-style date and time functions, such as std::time_t, std::difftime, and CLOCKS_PER_SEC.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[править] Пример

Этот пример отображает информацию о времени выполнения вызова функции
Original:
This example displays information about the execution time of a function call:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

#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";
}

Возможный вывод:

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