2
2
description : " Learn more about: `chrono` literals"
3
3
title : " chrono literals"
4
4
f1_keywords : ["chrono/std::literals::chrono_literals", "std::literals::chrono_literals", "chrono_literals"]
5
- ms.date : " 01/15 /2021"
5
+ ms.date : " 4/23 /2021"
6
6
---
7
7
# ` chrono ` literals
8
8
@@ -13,6 +13,9 @@ ms.date: "01/15/2021"
13
13
``` cpp
14
14
inline namespace literals {
15
15
inline namespace chrono_literals {
16
+ // return integral days
17
+ constexpr std::chrono::day operator ""d(unsigned long long d) noexcept;
18
+
16
19
// return integral hours
17
20
constexpr chrono::hours operator"" h(unsigned long long Val);
18
21
@@ -49,6 +52,8 @@ inline namespace literals {
49
52
// return floating-point nanoseconds
50
53
constexpr chrono::duration<double, nano> operator"" ns(long double Val);
51
54
55
+ // return integral year
56
+ constexpr chrono::year operator""y(unsigned long long y) noexcept; // C++ 20
52
57
} // inline namespace chrono_literals
53
58
} // inline namespace literals
54
59
```
@@ -62,7 +67,9 @@ The literals that take a **`long long`** argument return a value or the correspo
62
67
The following examples show how to use the `chrono` literals.
63
68
64
69
```cpp
65
- constexpr auto day = 24h;
70
+ constexpr auto day = 14d; // If the value > 255`, then the stored value is unspecified.
71
+ constexpr auto twoDays = 48h;
66
72
constexpr auto week = 24h* 7;
67
73
constexpr auto my_duration_unit = 108ms;
74
+ constexpr auto theYear = 2021y;
68
75
```
0 commit comments