mirror of
https://github.com/HowardHinnant/date.git
synced 2025-08-03 12:44:27 +02:00
Updated Examples and Recipes (markdown)
@@ -33,6 +33,7 @@ This page contains examples and recipes contributed by community members. Feel f
|
||||
- [Find and set UNIX download folder thanks to xdg-user-dir](#set_install_with_xdg_user_dir)
|
||||
- [Re-using unzoned date/time code for zoned date/time values (and vice versa)](#zoned2unzoned)
|
||||
- [Thoughts on reloading the IANA tzdb for long running programs](#tzdb_manage)
|
||||
- [Converting from Unix Time to date::year_month_day](#unixtime2yearmonthday)
|
||||
|
||||
***
|
||||
|
||||
@@ -2382,6 +2383,23 @@ It isn't the most friendly code to have to write. But on the other hand, it giv
|
||||
|
||||
More complex (and expensive) policies could track reference count usage for each tzdb and delete only when that reference count drops to zero. It is completely implementable externally without any privileged hooks into `"tz.h"`. This design is motivated by the "don't pay for what you don't use" philosophy.
|
||||
|
||||
<a name="unixtime2yearmonthday"></a>
|
||||
### The current local time
|
||||
(by [tommy bandzaw](https://github.com/bandzaw))
|
||||
|
||||
When working with APIs that gives you a timestamp as a plain integer, signed or not, for example a Unix Time, and you want to use it with chrono/date/time calculations, here's what one can do (instead of using the time_t & localtime):
|
||||
|
||||
```c++
|
||||
void callback(int unixtime)
|
||||
{
|
||||
auto t = std::chrono::seconds(unixtime);
|
||||
std::chrono::system_clock::time_point tp(t);
|
||||
auto d = date::floor<date::days>(tp);
|
||||
date::year_month_day ymd(d);
|
||||
date::month_day md(ymd.month(), ymd.day());
|
||||
}
|
||||
```
|
||||
|
||||
***
|
||||
|
||||
 _This work is licensed under a [Creative Commons Attribution 4.0 International License](http://creativecommons.org/licenses/by/4.0/)._
|
Reference in New Issue
Block a user