Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6631647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:34:32+00:00 2026-05-25T22:34:32+00:00

I need to get a nicely formatted timestamp (slightly modified ISO 8601) with millisecond

  • 0

I need to get a nicely formatted timestamp (slightly modified ISO 8601) with millisecond precision.

And example date would look like this: 2011-09-28 13:11:15.237-08:00
The formatting should be able to be overwridden as well.

I’ve been playing around with boost::posix_time::microsec_clock::local_time() and boost::posix_time::time_facet which works just fine except when it comes to timestamps.
Since posix time doesn’t contain time zone information this is just not possible (I’m guessing)

So, is there anything else I could use that has millisecond precision that contains timezone information or can I make the time_facet work with timezones?

Maybe I should always use UTC?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:34:33+00:00Added an answer on May 25, 2026 at 10:34 pm

    Have a look at the boost::local_time::local_date_time class. You can specify a time zone and use the local microsecond clock to initialize it like

    boost::local_time::local_date_time  my_ldt(boost::local_time::local_microsec_clock::local_time(new boost::local_time::posix_time_zone("EST-5EDT,M4.1.0,M10.5.0")));
    

    You should then be able to use the facets to format to a string.

    Edit: Full example:

    #include <iostream>
    #include <iomanip>
    #include <string>
    #include <sstream>
    
    #include <boost/date_time/local_time/local_time.hpp>
    
    int main(void)
    {
        boost::posix_time::ptime  now = boost::posix_time::second_clock::local_time();
        boost::posix_time::ptime  utc = boost::posix_time::second_clock::universal_time();
    
        boost::posix_time::time_duration tz_offset = (now - utc);
    
        std::stringstream   ss;
        boost::local_time::local_time_facet* output_facet = new boost::local_time::local_time_facet();
        ss.imbue(std::locale(std::locale::classic(), output_facet));
    
        output_facet->format("%H:%M:%S");
        ss.str("");
        ss << tz_offset;
    
        boost::local_time::time_zone_ptr    zone(new boost::local_time::posix_time_zone(ss.str().c_str()));
        boost::local_time::local_date_time  ldt = boost::local_time::local_microsec_clock::local_time(zone);
        boost::local_time::local_time_facet* output_facet = new boost::local_time::local_time_facet();
        ss.imbue(std::locale(std::locale::classic(), output_facet));
        output_facet->format("%Y-%m-%d %H:%M:%S%f%Q");
        ss.str("");
        ss << ldt;
        std::cout << ss.str() << std::endl; // "2004-02-29 12:34:56.000789-05:00"
    
        std::cout << "Press return to exit" << std::endl;
        std::string wait_for_line;
        std::getline(std::cin, wait_for_line);
    
        return (0);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am migrating some code and have nicely formatted Look-up Tables but they have
Just need get some vals located in application.ini(main ini) in the Controller plugin I
I need get all items these have no categories int? categoryId = null; var
I'm working with C#.net developing applications for windows mobile 6, and i need get
I have two tables with a weak relation. I need get a text value
Need to get the 10 word before and 10 words after for the given
I need to get the default printer name. I'll be using C# but I
I need to get a log of user access to our SQL Server so
I need to get the first and last day of a month in the
I need to get some information that is contained in the MFT on a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.