mirror of
https://github.com/HowardHinnant/date.git
synced 2025-08-06 14:14:27 +02:00
Updated Boost datetime Examples Translated (markdown)
@@ -516,7 +516,6 @@ an example using the IANA timezone database see the [Local to UTC Conversion](#L
|
|||||||
<a name="Flight_Time_Example"></a>
|
<a name="Flight_Time_Example"></a>
|
||||||
###Flight Time Example
|
###Flight Time Example
|
||||||
|
|
||||||
#include "date.h"
|
|
||||||
#include "tz.h"
|
#include "tz.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@@ -527,27 +526,20 @@ an example using the IANA timezone database see the [Local to UTC Conversion](#L
|
|||||||
using namespace date;
|
using namespace date;
|
||||||
|
|
||||||
// set up some timezones for creating and adjusting local times
|
// set up some timezones for creating and adjusting local times
|
||||||
auto nyc_tz = locate_zone("America/New_York");
|
|
||||||
auto phx_tz = locate_zone("America/Phoenix");
|
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
|
// local departure time in phoenix is 11 pm on March 30 2005
|
||||||
// (ny changes to dst on apr 3 at 2 am)
|
// (ny changes to dst on apr 3 at 2 am)
|
||||||
auto phx_departure = sys_days(2005_y/mar/30) + 23h + 0min;
|
auto phx_departure = make_zoned(phx_tz, local_days{2005_y/mar/30} + 23h);
|
||||||
auto utc_departure = phx_tz->to_sys(phx_departure);
|
|
||||||
|
|
||||||
auto flight_length = 4h + 30min;
|
// flight is 4 hours, 30 minutes
|
||||||
auto utc_arrival = utc_departure + flight_length;
|
auto phx_arrival = make_zoned(phx_tz, phx_departure.get_sys_time() + 4h + 30min);
|
||||||
|
auto nyc_arrival = make_zoned(nyc_tz, phx_arrival);
|
||||||
auto phx_arrival = phx_tz->to_local(utc_arrival);
|
|
||||||
auto nyc_arrival = nyc_tz->to_local(utc_arrival);
|
|
||||||
|
|
||||||
std::cout << "departure phx time: " << phx_departure << '\n';
|
std::cout << "departure phx time: " << phx_departure << '\n';
|
||||||
std::cout << "arrival phx time: "
|
std::cout << "arrival phx time: " << phx_arrival << '\n';
|
||||||
<< floor<minutes>(phx_arrival)
|
std::cout << "arrival nyc time: " << nyc_arrival << '\n';
|
||||||
<< ' ' << phx_arrival.second << '\n';
|
|
||||||
std::cout << "arrival nyc time: "
|
|
||||||
<< floor<minutes>(nyc_arrival)
|
|
||||||
<< ' ' << nyc_arrival.second << '\n';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
|
Reference in New Issue
Block a user