time with libboost_date_time

G

Gary Wessle

Hi

could someone please tell us how to do this:
my PC time is set to Australia/Sydney.
I need New York time epoch using libboost_date_time

thank you


#include <iostream>
#include "boost/date_time/local_time/local_time.hpp"
#include "boost/date_time/posix_time/posix_time.hpp"
using namespace std;

int main(){

using namespace boost::gregorian;
using namespace boost::local_time;
using namespace boost::posix_time;

// get the PC time and make sure it stays correct
ptime now = second_clock::local_time(); // current PC time
cout << "Your computer time is: " << now << endl;

// load time zone conversion date form file
tz_database tz_db;
tz_db.load_from_file("../date_time_zonespec.csv");
time_zone_ptr nyc_tz = tz_db.time_zone_from_region("America/New_York");
time_zone_ptr syd_tz = tz_db.time_zone_from_region("Australia/Sydney");


/* ................ so fare so good ................ */


// Convert it to NY time epoch (not sure how)
local_date_time in_sydney(now, syd_tz, local_date_time::NOT_DATE_TIME_ON_ERROR);
local_date_time in_ny = in_sydney.local_time_in(nyc_tz);

cout << "\nNow in New York " << in_ny << endl;

}
 
G

Gary Wessle

Gary Wessle said:
Hi

could someone please tell us how to do this:
my PC time is set to Australia/Sydney.
I need New York time epoch using libboost_date_time

thank you


#include <iostream>
#include "boost/date_time/local_time/local_time.hpp"
#include "boost/date_time/posix_time/posix_time.hpp"
using namespace std;

int main(){

using namespace boost::gregorian;
using namespace boost::local_time;
using namespace boost::posix_time;

// get the PC time and make sure it stays correct
ptime now = second_clock::local_time(); // current PC time
cout << "Your computer time is: " << now << endl;

// load time zone conversion date form file
tz_database tz_db;
tz_db.load_from_file("../date_time_zonespec.csv");
time_zone_ptr nyc_tz = tz_db.time_zone_from_region("America/New_York");
time_zone_ptr syd_tz = tz_db.time_zone_from_region("Australia/Sydney");


/* ................ so fare so good ................ */


// Convert it to NY time epoch (not sure how)
local_date_time in_sydney(now, syd_tz, local_date_time::NOT_DATE_TIME_ON_ERROR);
local_date_time in_ny = in_sydney.local_time_in(nyc_tz);

cout << "\nNow in New York " << in_ny << endl;

}

OR

// exctact the date and duration since 00:00:00 from now
date in_date(2004,10,04); // example
time_duration td(12,14,32); // example
// create the local_date_time in sydney
local_date_time syd_time(in_date,
td,
syd_tz,
local_date_time::NOT_DATE_TIME_ON_ERROR);
/* but how can I get date and time_duration form now */
/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/

// convert it to New York
local_date_time in_ny = in_sydney.local_time_in(nyc_tz);

// print time now in New York.
cout << "\nNow in New York " << in_ny << endl;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,069
Latest member
SimplyleanKetoReviews

Latest Threads

Top