mirror of
https://github.com/HowardHinnant/date.git
synced 2025-08-04 21:24:26 +02:00
Updated Boost datetime Examples Translated (markdown)
@@ -480,44 +480,44 @@ main()
|
|||||||
```
|
```
|
||||||
<a name="Flight_Time_Example"></a>
|
<a name="Flight_Time_Example"></a>
|
||||||
### Flight Time Example
|
### Flight Time Example
|
||||||
|
```c++
|
||||||
|
#include "tz.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include "tz.h"
|
int
|
||||||
#include <iostream>
|
main()
|
||||||
|
{
|
||||||
|
using namespace std::chrono;
|
||||||
|
using namespace date;
|
||||||
|
|
||||||
int
|
// set up some timezones for creating and adjusting local times
|
||||||
main()
|
auto phx_tz = locate_zone("America/Phoenix");
|
||||||
{
|
auto nyc_tz = locate_zone("America/New_York");
|
||||||
using namespace std::chrono;
|
|
||||||
using namespace date;
|
|
||||||
|
|
||||||
// set up some timezones for creating and adjusting local times
|
// local departure time in phoenix is 11 pm on March 30 2005
|
||||||
auto phx_tz = locate_zone("America/Phoenix");
|
// (ny changes to dst on apr 3 at 2 am)
|
||||||
auto nyc_tz = locate_zone("America/New_York");
|
auto phx_departure = make_zoned(phx_tz, local_days{2005_y/mar/30} + 23h);
|
||||||
|
|
||||||
// local departure time in phoenix is 11 pm on March 30 2005
|
// flight is 4 hours, 30 minutes
|
||||||
// (ny changes to dst on apr 3 at 2 am)
|
auto phx_arrival = make_zoned(phx_tz, phx_departure.get_sys_time() + 4h + 30min);
|
||||||
auto phx_departure = make_zoned(phx_tz, local_days{2005_y/mar/30} + 23h);
|
auto nyc_arrival = make_zoned(nyc_tz, phx_arrival);
|
||||||
|
|
||||||
// flight is 4 hours, 30 minutes
|
std::cout << "departure phx time: " << phx_departure << '\n';
|
||||||
auto phx_arrival = make_zoned(phx_tz, phx_departure.get_sys_time() + 4h + 30min);
|
std::cout << "arrival phx time: " << phx_arrival << '\n';
|
||||||
auto nyc_arrival = make_zoned(nyc_tz, phx_arrival);
|
std::cout << "arrival nyc time: " << nyc_arrival << '\n';
|
||||||
|
}
|
||||||
std::cout << "departure phx time: " << phx_departure << '\n';
|
|
||||||
std::cout << "arrival phx time: " << phx_arrival << '\n';
|
|
||||||
std::cout << "arrival nyc time: " << nyc_arrival << '\n';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Output:
|
|
||||||
//
|
|
||||||
// departure phx time: 2005-03-30 23:00
|
|
||||||
// arrival phx time: 2005-03-31 03:30 MST
|
|
||||||
// arrival nyc time: 2005-03-31 05:30 EST
|
|
||||||
//
|
|
||||||
// Note that boost states a nyc_arrival time of 2005-Mar-31 06:30:00 EDT
|
|
||||||
// because boost uses the current US daylightsavings rules as opposed to
|
|
||||||
// those that were in effect in 2005. This library varies its DST rules
|
|
||||||
// with the date.
|
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
//
|
||||||
|
// departure phx time: 2005-03-30 23:00
|
||||||
|
// arrival phx time: 2005-03-31 03:30 MST
|
||||||
|
// arrival nyc time: 2005-03-31 05:30 EST
|
||||||
|
//
|
||||||
|
// Note that boost states a nyc_arrival time of 2005-Mar-31 06:30:00 EDT
|
||||||
|
// because boost uses the current US daylightsavings rules as opposed to
|
||||||
|
// those that were in effect in 2005. This library varies its DST rules
|
||||||
|
// with the date.
|
||||||
|
```
|
||||||
<a name="Seconds_Since_Epoch"></a>
|
<a name="Seconds_Since_Epoch"></a>
|
||||||
### Seconds Since Epoch
|
### Seconds Since Epoch
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user