• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "boost/date_time/gregorian/gregorian.hpp"
2 #include "boost/date_time/posix_time/posix_time.hpp"
3 #include "boost/date_time/local_time/local_time.hpp"
4 #include <iostream>
5 #include <locale>
6 
main()7 int main() {
8   using namespace boost::gregorian;
9   using namespace boost::posix_time;
10   using namespace boost::local_time;
11 
12   tz_database tz_db;
13   try {
14     tz_db.load_from_file("../../data/date_time_zonespec.csv");
15   }catch(data_not_accessible dna) {
16     std::cerr << "Error with time zone data file: " << dna.what() << std::endl;
17     exit(EXIT_FAILURE);
18   }catch(bad_field_count bfc) {
19     std::cerr << "Error with time zone data file: " << bfc.what() << std::endl;
20     exit(EXIT_FAILURE);
21   }
22 
23   time_zone_ptr nyc = tz_db.time_zone_from_region("America/New_York");
24   local_date_time ny_time(date(2004, Aug, 30), hours(10), nyc, true);
25 
26   typedef boost::date_time::time_facet<local_date_time, char> ldt_facet;
27   ldt_facet* timefacet = new ldt_facet("%Y-%b-%d %H:%M:%S""%F %Z");
28   std::locale loc(std::locale::classic(), timefacet);
29 
30   std::cout << ny_time << std::endl;
31   // 2004-Aug-30 10:00:00 EDT
32   std::cout.imbue(loc);
33   std::cout << ny_time << std::endl;
34   // 2004-Aug-30 10:00:00 Eastern Daylight Time
35 
36   return 0;
37 }
38 
39 
40 /*  Copyright 2004-2005: CrystalClear Software, Inc
41  *  http://www.crystalclearsoftware.com
42  *
43  *  Subject to the Boost Software License, Version 1.0.
44  * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
45  */
46