Date and time utilities
Da cppreference.com
< cpp
![]() |
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
C + + inclui suporte para dois tipos de manipulação do 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.
- A biblioteca
chrono
, um conjunto de tipos flexíveis que controlam o tempo com graus variáveis de precisão (por exemplo, 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. - C-estilo biblioteca de data e hora (por exemplo 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.
Índice |
[editar] NJ biblioteca
A biblioteca
chrono
define três tipos principais (durações, relógios e pontos de tempo), bem como fun��ões de utilidade e typedefs comuns.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.
[editar] Duração
A duração é constituído por um espaço de tempo, definida como um número de períodos de alguma unidade de tempo. Por exemplo, "42 segundos" pode ser representado por uma duração que consiste de 42 período de uma unidade de tempo de 1 segundo.
Defined in header
<chrono> | |
Defined in namespace
std::chrono | |
(C++11) |
um intervalo de 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. (modelo de classe) |
[editar] Relógios
Um relógio consiste em um ponto de partida (ou época) e uma taxa de tick. Por exemplo, um relógio pode ter uma época de 01 de janeiro de 1970 e marcar a cada segundo. C + + define três tipos de relógio:
Defined in header
<chrono> | |
Defined in namespace
std::chrono | |
(C++11) |
tempo de relógio do relógio do sistema à escala em tempo real 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) |
relógio monotônico que nunca vai ser ajustado 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) |
o relógio com o menor período de carrapato disponível 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) |
[editar] Tempo ponto
Um ponto de tempo é a duração de tempo que passou desde a época do relógio específico.
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.
Defined in header
<chrono> | |
Defined in namespace
std::chrono | |
(C++11) |
a point in time (modelo de classe) |
[editar] C estilo de data e biblioteca de tempo
Também são fornecidos as funções estilo C de data e hora, como 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.
[editar] Exemplo
Este exemplo exibe informações sobre o tempo de execução de uma chamada de função:
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"; }
Potencial saída:
finished computation at Sat Jun 16 20:42:57 2012 elapsed time: 3s