Date and time utilities
Da cppreference.com.
< cpp
![]() |
Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate.
La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui. |
C++ include il supporto per due tipi di manipolazione del tempo:
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.
You can help to correct and verify the translation. Click here for instructions.
- La libreria
chrono
, un insieme flessibile di tipi che tengono traccia del tempo con vari gradi di precisione (ad esempio std::chrono::time_point).Original:Thechrono
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. - La libreria in stile C per gestire data e ora (ad esempio 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.
Indice |
[modifica] NJ libreria
La libreria
chrono
definisce tre tipi principali (durata, orologi, e punti di tempo), nonché le funzioni di utilità e typedef comuni.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.
You can help to correct and verify the translation. Click here for instructions.
[modifica] Durata
Una durata consiste in un arco di tempo, definito come un certo numero di tick di qualche unità di tempo. Per esempio, "42 secondi" potrebbe essere rappresentato da una durata composta da 42 tick di un 1 secondo.
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.
You can help to correct and verify the translation. Click here for instructions.
Definizione nell'header
<chrono> | |
Defined in namespace
std::chrono | |
(C++11) |
un intervallo di tempo 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 template) |
[modifica] Orologi
Un orologio è composto da un punto di partenza (o epoca) e un periodo di tick. Ad esempio, un orologio può avere un epoca al 1 ° gennaio 1970 e tick ogni secondo. C++ definisce tre tipi di clock:
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.
You can help to correct and verify the translation. Click here for instructions.
Definizione nell'header
<chrono> | |
Defined in namespace
std::chrono | |
(C++11) |
orologio da parete dal livello di sistema orologio in tempo reale 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) |
(C++11) |
orologio monotona che non verrà mai modificato 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) |
(C++11) |
l'orologio con il più breve periodo di zecca disponibili 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) |
[modifica] Punto nel tempo
Un punto nel tempo è un periodo di tempo che è passato dell'epoca specificata nell'orologio .
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.
You can help to correct and verify the translation. Click here for instructions.
Definizione nell'header
<chrono> | |
Defined in namespace
std::chrono | |
(C++11) |
a point in time (classe template) |
[modifica] C-stile di data e ora libreria
Ci sono anche le funzioni in C-stile per gestire data e ora, come std::time_t, std::difftime e 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.
You can help to correct and verify the translation. Click here for instructions.
[modifica] Esempio
In questo esempio vengono visualizzate informazioni sul tempo di esecuzione di una chiamata di funzione:
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.
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"; }
Possible output:
finished computation at Sat Jun 16 20:42:57 2012 elapsed time: 3s