Espaces de noms
Variantes
Affichages
Actions

Date and time utilities

De cppreference.com
< cpp


C + + prend en charge les deux types de manipulation du temps:
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.
  • La bibliothèque chrono, une collection souple de types qui suivent le temps avec des degrés de précision (par exemple 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-bibliothèque de style date et l'heure (par exemple 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.

Sommaire

[modifier] NJ bibliothèque

La bibliothèque chrono définit trois types principaux (durées, des horloges et des points de temps) ainsi que des fonctions d'utilité et typedefs communs .
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.

[modifier] Durée

Une durée consiste en un laps de temps, défini comme un nombre de graduations de certaines unités de temps. Par exemple, "42 secondes" pourrait être représentée par une durée, composé de 42 ticks d'une unité de temps de 1 seconde .
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.
Defined in header <chrono>
Defined in namespace std::chrono
(C++11)
un intervalle de temps
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.

(classe générique) [edit]

[modifier] Horloges

Une horloge se compose d'un point de départ (ou d'une époque) et un taux de tique. Par exemple, une horloge peut avoir une époque de Janvier 1, 1970 et cocher chaque seconde. C + + définit trois types d'horloges:
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.
Defined in header <chrono>
Defined in namespace std::chrono
temps d'horloge à partir de la paroi de l'ensemble du système d'horloge en temps réel
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.

(classe) [edit]
horloge monotone qui ne sera jamais réglée
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.

(classe) [edit]
l'horloge avec la période la plus courte tiques disponibles
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.

(classe) [edit]

[modifier] Heure point

Un point dans le temps est une durée de temps qui s'est écoulé depuis l'époque de l'horloge spécifique .
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.
Defined in header <chrono>
Defined in namespace std::chrono
(C++11)
a point in time
(classe générique) [edit]

[modifier] C-style de date et d'une bibliothèque de temps

On trouvera aussi les fonctions de style C date et l'heure, comme std::time_t, std::difftime et 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.

[modifier] Exemple

Cet exemple affiche des informations sur le temps d'exécution d'un appel de fonction:
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";
}

Résultat possible :

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