mirror of
https://github.com/HowardHinnant/date.git
synced 2025-08-05 21:54: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>
|
||||
###Flight Time Example
|
||||
|
||||
#include "date.h"
|
||||
#include "tz.h"
|
||||
#include <iostream>
|
||||
|
||||
@@ -527,27 +526,20 @@ an example using the IANA timezone database see the [Local to UTC Conversion](#L
|
||||
using namespace date;
|
||||
|
||||
// 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 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 = sys_days(2005_y/mar/30) + 23h + 0min;
|
||||
auto utc_departure = phx_tz->to_sys(phx_departure);
|
||||
auto phx_departure = make_zoned(phx_tz, local_days{2005_y/mar/30} + 23h);
|
||||
|
||||
auto flight_length = 4h + 30min;
|
||||
auto utc_arrival = utc_departure + flight_length;
|
||||
|
||||
auto phx_arrival = phx_tz->to_local(utc_arrival);
|
||||
auto nyc_arrival = nyc_tz->to_local(utc_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: "
|
||||
<< floor<minutes>(phx_arrival)
|
||||
<< ' ' << phx_arrival.second << '\n';
|
||||
std::cout << "arrival nyc time: "
|
||||
<< floor<minutes>(nyc_arrival)
|
||||
<< ' ' << nyc_arrival.second << '\n';
|
||||
std::cout << "arrival phx time: " << phx_arrival << '\n';
|
||||
std::cout << "arrival nyc time: " << nyc_arrival << '\n';
|
||||
}
|
||||
|
||||
// Output:
|
||||
|
Reference in New Issue
Block a user