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

  • SEARCH
  • Home
  • 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 8687205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:03:48+00:00 2026-06-12T23:03:48+00:00

How to convert std::chrono::time_point to calendar datetime string with fractional seconds? For example: 10-10-2012

  • 0

How to convert std::chrono::time_point to calendar datetime string with fractional seconds?

For example:

"10-10-2012 12:38:40.123456"
  • 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-06-12T23:03:49+00:00Added an answer on June 12, 2026 at 11:03 pm

    If system_clock, this class have time_t conversion.

    #include <iostream>
    #include <chrono>
    #include <ctime>
    
    using namespace std::chrono;
    
    int main()
    {
      system_clock::time_point p = system_clock::now();
    
      std::time_t t = system_clock::to_time_t(p);
      std::cout << std::ctime(&t) << std::endl; // for example : Tue Sep 27 14:21:13 2011
    }
    

    example result:

    Thu Oct 11 19:10:24 2012
    

    EDIT:
    But, time_t does not contain fractional seconds.
    Alternative way is to use time_point::time_since_epoch() function. This function returns duration from epoch.
    Follow example is milli second resolution’s fractional.

    #include <iostream>
    #include <chrono>
    #include <ctime>
    
    using namespace std::chrono;
    
    int main()
    {
      high_resolution_clock::time_point p = high_resolution_clock::now();
    
      milliseconds ms = duration_cast<milliseconds>(p.time_since_epoch());
    
      seconds s = duration_cast<seconds>(ms);
      std::time_t t = s.count();
      std::size_t fractional_seconds = ms.count() % 1000;
    
      std::cout << std::ctime(&t) << std::endl;
      std::cout << fractional_seconds << std::endl;
    }
    

    example result:

    Thu Oct 11 19:10:24 2012
    
    925
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How interoperable are boost::date_time and std::chrono? For example, is there a way to convert
i am getting an problem string ccc=example; int cc=atoi(csession); it says cannot convert ‘std::string’
How to convert std::chrono::monotonic_clock::now() to milliseconds and cast it to long? using steady_clock or
I'm trying to convert std::string to float/double . I tried: std::string num = 0.6;
Possible Duplicate: C++ std::string conversion problem on Windows How to convert std::string to LPCSTR?
What's the easiest way to convert a C++ std::string to another std::string, which has
I have unsigned char* , want to convert it to std::string . Can you
I'm trying to use std::ostringstream to convert a number into a string (char *),
In my C++ program I want to convert a std:string like this: abc €
I am trying to write a function to convert a std::string to char* .

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.