Search code examples
c++boostboost-date-time

Is there a way to get regional time format with Boost?


as I tried to ask in my title, I am talking about regional time format. I have an application that can display the time/date, but from US users I get the question of why am I displaying the time like this: 21:30 instead of this: 9:30PM. Same thing for the date to which I display the date as 22.05.2018 instead of 05.22.2018.

So my questions is: Is there a way to achieve getting a timezone flag or location or even the time already formatted so that I can display the time/date different for different regions?


Solution

  • With Boost Locale

    double now=time(0);
    cout << as::datetime << as::local_time << "Local time is: "<< now << endl;
    cout << as::gmt << "GMT Time is: "<< now <<endl;
    cout << as::time_zone("EST") << "Eastern Standard Time is: "<< now <<endl;
    

    Parse date from string back and add the time-zone