mirror of
https://github.com/HowardHinnant/date.git
synced 2025-08-04 13:14:26 +02:00
Updated Boost datetime Examples Translated (markdown)
@@ -480,44 +480,44 @@ main()
|
||||
```
|
||||
<a name="Flight_Time_Example"></a>
|
||||
### Flight Time Example
|
||||
```c++
|
||||
#include "tz.h"
|
||||
#include <iostream>
|
||||
|
||||
#include "tz.h"
|
||||
#include <iostream>
|
||||
int
|
||||
main()
|
||||
{
|
||||
using namespace std::chrono;
|
||||
using namespace date;
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
using namespace std::chrono;
|
||||
using namespace date;
|
||||
// set up some timezones for creating and adjusting local times
|
||||
auto phx_tz = locate_zone("America/Phoenix");
|
||||
auto nyc_tz = locate_zone("America/New_York");
|
||||
|
||||
// set up some timezones for creating and adjusting local times
|
||||
auto phx_tz = locate_zone("America/Phoenix");
|
||||
auto nyc_tz = locate_zone("America/New_York");
|
||||
// local departure time in phoenix is 11 pm on March 30 2005
|
||||
// (ny changes to dst on apr 3 at 2 am)
|
||||
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
|
||||
// (ny changes to dst on apr 3 at 2 am)
|
||||
auto phx_departure = make_zoned(phx_tz, local_days{2005_y/mar/30} + 23h);
|
||||
// flight is 4 hours, 30 minutes
|
||||
auto phx_arrival = make_zoned(phx_tz, phx_departure.get_sys_time() + 4h + 30min);
|
||||
auto nyc_arrival = make_zoned(nyc_tz, phx_arrival);
|
||||
|
||||
// flight is 4 hours, 30 minutes
|
||||
auto phx_arrival = make_zoned(phx_tz, phx_departure.get_sys_time() + 4h + 30min);
|
||||
auto nyc_arrival = make_zoned(nyc_tz, phx_arrival);
|
||||
|
||||
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.
|
||||
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.
|
||||
```
|
||||
<a name="Seconds_Since_Epoch"></a>
|
||||
### Seconds Since Epoch
|
||||
|
||||
|
Reference in New Issue
Block a user