|
Boost Users : |
From: Fred J. (phddas_at_[hidden])
Date: 2007-02-06 20:41:24
Dear all.
I am trying to get New York time in time_t epoch now. my PC is set to Sydney time. please help
thanks
here is my effort fro the last 4 hours.
#include <fstream>
#include <ios>
#include <iostream>
#include <string>
#include "boost/date_time/local_time/local_time.hpp"
#include "boost/date_time/posix_time/posix_time.hpp"
#include "boost/date_time/local_time_adjustor.hpp"
#include "boost/date_time/c_local_time_adjustor.hpp"
using namespace std;
int main(){
using namespace boost::gregorian;
using namespace boost::local_time;
using namespace boost::posix_time;
// now time is
ptime now = second_clock::local_time(); // current PC time
cout << "Your computer time is: " << now << endl;
// typedef boost::date_time::c_local_adjustor<ptime> local_adj;
// // create a sydney time
// ptime sydtime(date(2007,02,07), hours(12)+minutes(9)+seconds(32));
// cout << "Sydney local time is: " << to_simple_string( sydtime ) << 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");
// create a sydney time from date and time_duration
date in_date(2007,02,07);
time_duration td(12,25,32);
local_date_time sydtime(in_date,
td,
syd_tz,
local_date_time::NOT_DATE_TIME_ON_ERROR);
cout << "Sydney time is: " << sydtime << endl;
cout << "in UTC it is: " << sydtime.utc_time() << endl;
// // convrt sydney to utc
// ptime syd_t_utc = local_adj::local_to_utc( sydtime );
// cout << "UTC time is: " << to_simple_string( syd_t_utc ) << endl;
// // conver it to new york
// time_zone_ptr nyc_tz = tz_db.time_zone_from_region("America/New_York");
// ptime nytime = nyc_tz::utc_to_local( nyc_tz );
// cout << "New York local time is: " << to_simple_string( nyctime ) << endl;
}
---------------------------------
Any questions? Get answers on any topic at Yahoo! Answers. Try it now.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net