jeudi 28 novembre 2019

Get date time inC++ until milisconds [duplicate]

This question already has an answer here:

I used code below to get date time in c++.

    std::time_t t = std::time(0);
    std::tm* now = std::localtime(&t);

    int year = now->tm_year + 1900;
    int month = now->tm_mon + 1;
    int day = now->tm_mday;
    int hour = now->tm_hour;
    int min = now->tm_min;
    int sec = now->tm_sec;

    strstream tstamp_abs;
    tstamp_abs << year << "-" << month << "-" << day << " " << hour << ":" << min << ":" << sec;

My qustion is, how do I get the miliseconds?

I want result similar to python code:

from datetime import datetime
dateTimeObj = datetime.now()

The python code give result: 2019-11-29 11:15:39.192310

With c+ code, I only get the integer part of the seconds.I need to get more accurate milisecods.

Aucun commentaire:

Enregistrer un commentaire