Timeline for How can I format a duration with std::println?
Current License: CC BY-SA 4.0
Post Revisions
16 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| yesterday | history | became hot network question | |||
| yesterday | answer | added | r5g5 | timeline score: 1 | |
| yesterday | comment | added | Howard Hinnant | Your question performs chronological arithmetic, but also hints that you may desire calendrical arithmetic. In <chrono> you can do either. Chronological arithmetic operates on fixed units of time. Calendrical arithmetic follows the irregularity of calendars. See this SO Q/A for more details: stackoverflow.com/q/43010362/576911. This concentrates on months arithmetic but the same analogous behavior is also true for years. | |
| yesterday | vote | accept | Angle.Bracket | ||
| yesterday | vote | accept | Angle.Bracket | ||
| yesterday | |||||
| yesterday | answer | added | Drew Dormann | timeline score: 9 | |
| yesterday | history | edited | wohlstad | CC BY-SA 4.0 |
added 11 characters in body
|
| yesterday | answer | added | Toby Speight | timeline score: 12 | |
| yesterday | comment | added | Toby Speight | Yes, that's expected. From beginning of 2025 to beginning of 2026 is less than 31556952 seconds; rounding down gives 0. You perhaps want to convert to floating-point year duration? | |
| yesterday | comment | added | Marek R |
I've missed that table is split and year specifiers are in "invalid part": The following specifiers are recognized, but will cause std::format_error to be thrown:
|
|
| yesterday | answer | added | Caleth | timeline score: 7 | |
| yesterday | comment | added | Angle.Bracket | @MarekR that's right, tried that as well | |
| yesterday | comment | added | Angle.Bracket |
@TobySpeight thanks, duration.count() does not print the unit, but yields 0 for e.g. 01.01.2025and 01.01.2026
|
|
| yesterday | comment | added | Marek R |
Format strings are documented here, but it seams it doesn't work for year specific parts like %Y: godbolt.org/z/jfsxYeaqj It works for %T.
|
|
| yesterday | comment | added | Toby Speight |
The result is 1 (as it has been rounded down) - the [31556952]s is the unit. Use duration.count() if you don't want that printed.
|
|
| yesterday | history | asked | Angle.Bracket | CC BY-SA 4.0 |