Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This clock can represent the range and resolution of file time values used in the file system.
Syntax
using file_clock = std::filesystem::_File_time_clock; // C++20
Remarks
In the Microsoft implementation, the epoch, or the time from which the file_clock starts measuring time, is 1/1/1601 00:00:00.
The ISO C++ Standard provides a choice between providing to_sys() and from_sys(), or to_utc() and from_utc(). The Microsoft implementation chose to_utc and from_utc.
Members
| Name | Description | 
|---|---|
| from_utc | Static. Converts a utc_timeto afile_time. | 
| now | Static. Returns the current International Atomic Time. | 
| to_utc | Static. Converts a file_timetoutc_time. | 
Non-members
| Name | Description | 
|---|---|
| from_stream | Parse a file_clockfrom the given stream using the specified format. | 
| operator<< | Output file_timeto the given stream. | 
Convenience type aliases
| Name | Description | 
|---|---|
| file_clock::duration | In Microsoft's implementation, it's a synonym for duration<long long, ratio<1, 10'000'000>. It represents a duration of time measured in units of 100 nanoseconds. | 
| file_clock::time_point | A synonym for time_point<File_time_clock>. Used to represent atime_pointfor this clock. | 
| file_clock::period | In Microsoft's implementation, it's a synonym for ratio<1, 10'000'000>. It represents the time in seconds (100 nanoseconds) between each tick in the duration. | 
| file_clock::rep | A synonym for the type ( long long)  used to represent the integral units in this clock'sfile_clock::duration. | 
Related
| Name | Description | 
|---|---|
| file_time | A synonym for time_point<file_clock, Duration>. Represents atime_pointfor afile_clock. You specify theDuration. Defined instd::chrono | 
Public constants
| Name | Description | 
|---|---|
| file_clock::is_steady constant | Indicates whether the clock type is steady. Its value is false. | 
Requirements
Header: <chrono> (since C++20)
Namespace: std::chrono
Compiler Option: /std:c++latest
 from_utc
Static method that converts a utc_time to a file_time.
template <class Duration>
static file_time<common_type_t<_Duration, chrono::seconds>>
from_utc(const utc_time<Duration>& t);
Parameters
t
The utc_time to convert.
Return value
A file_time that represents the equivalent utc_time as t. It's calculated as utc_clock::to_sys(utc_time).time_since_epoch() minus the number of leap seconds before January 1, 2017 (27). Windows 10 version 1809 and Windows Server 2019 introduced support for leap seconds. That support is enabled by default, though it can be disabled. When enabled, only leap seconds after July 2018 (not the ones between January 1, 2017 and July 2018) are included in the time.
We recommend you use std::chrono::clock_cast to convert time points between clocks rather than call this function directly. This is particularly relevant for file_clock because the ISO C++ Standard allows this type to define either to_utc and from_utc, or to_sys and from_sys. Since which is implemented may vary by vendor, you can use clock_cast instead, which is provided by all library vendors.
Example: from_utc
// compile using: /std:c++latest
#include <iostream>
#include <chrono>
using namespace std::chrono;
int main()
{
    std::cout << clock_cast<file_clock>(utc_clock::now());
    return 0;
}
2021-08-17 00:20:41.2594557
 to_utc
Static method that converts a file_time to a utc_time.
template <class Duration>
static utc_time<common_type_t<Duration, seconds>>
to_utc(const file_time<Duration>& t);
Parameters
t
The file_time to convert.
Return Value
A utc_time that represents the equivalent file_time as t. We recommend you use std::chrono::clock_cast to convert time points between clocks, rather than call this function directly. This is particularly relevant for file_clock because the ISO C++ Standard allows this type to define either to_utc and from_utc, or to_sys and from_sys. Since which is implemented may vary by vendor, you can use clock_cast instead, which is provided by all library vendors.
Example: to_utc
// compile using: /std:c++latest
#include <iostream>
#include <chrono>
using namespace std::chrono;
int main()
{
    std::cout << clock_cast<std::chrono::utc_clock>(file_clock::now());
    return 0;
}
2021-08-17 00:20:41.2594557
 is_steady
Static value that specifies whether the clock type is steady. In the Microsoft implementation, is_steady is false. This makes this clock unsuitable for measuring how long an operation takes because an unsteady clock can be adjusted while you're timing something so the measured time may be off or even negative. Use a high_resolution_clock to time events, instead.
static const bool is_steady = false;
now
Static method that returns the current system time, with nanosecond resolution, adjusted by the epoch of the file_clock.
static time_point now() noexcept;
Return Value
A time_point object that represents the current time.
See also
<chrono>
gps_clock class
high_resolution_clock
local_t struct
steady_clock struct
system_clock struct
tai_clock class
utc_clock class
Header Files Reference