mirror of
https://github.com/HowardHinnant/date.git
synced 2025-08-05 05:34:27 +02:00
Updated Examples and Recipes (markdown)
@@ -24,6 +24,7 @@ This page contains examples and recipes contributed by community members. Feel f
|
|||||||
- [How many timezones are using daylight saving?](#tz_daylight)
|
- [How many timezones are using daylight saving?](#tz_daylight)
|
||||||
- [What is the epoch difference between Unix Time and GPS time?](#unix_gps_epoch_diff)
|
- [What is the epoch difference between Unix Time and GPS time?](#unix_gps_epoch_diff)
|
||||||
- [How to convert to/from C++ Builder's TDate and TDateTime](#TDate)
|
- [How to convert to/from C++ Builder's TDate and TDateTime](#TDate)
|
||||||
|
- [How to convert to/from QDate](#QDate)
|
||||||
|
|
||||||
***
|
***
|
||||||
|
|
||||||
@@ -1215,6 +1216,30 @@ which outputs:
|
|||||||
-1.25
|
-1.25
|
||||||
35065
|
35065
|
||||||
|
|
||||||
|
<a name="QDate"></a>
|
||||||
|
### How to convert to/from QDate
|
||||||
|
(by [Howard Hinnant](https://github.com/HowardHinnant))
|
||||||
|
|
||||||
|
Here are functions you can use to convert between [`QDate`](http://doc.qt.io/qt-5/qdate.html) and `sys_days`:
|
||||||
|
|
||||||
|
date::sys_days
|
||||||
|
to_sys_days(QDate qd)
|
||||||
|
{
|
||||||
|
using namespace date;
|
||||||
|
return sys_days{days{qd.toJulianDay()} -
|
||||||
|
(sys_days{1970_y/jan/1} - sys_days{year{-4713}/nov/24})};
|
||||||
|
}
|
||||||
|
|
||||||
|
QDate
|
||||||
|
to_QDate(date::sys_days sd)
|
||||||
|
{
|
||||||
|
using namespace date;
|
||||||
|
return QDate::fromJulianDay((sd.time_since_epoch() +
|
||||||
|
(sys_days{1970_y/jan/1} - sys_days{year{-4713}/nov/24})).count());
|
||||||
|
}
|
||||||
|
|
||||||
|
These work by simply adjusting the epoch of these two types.
|
||||||
|
|
||||||
***
|
***
|
||||||
|
|
||||||
 _This work is licensed under a [Creative Commons Attribution 4.0 International License](http://creativecommons.org/licenses/by/4.0/)._
|
 _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