Converting epoch time to “real” date/time

后端 未结 6 668
情歌与酒
情歌与酒 2020-11-30 09:38

What I want to do is convert an epoch time (seconds since midnight 1/1/1970) to \"real\" time (m/d/y h:m:s)

So far, I have the following algorithm, which to me feels

6条回答
  •  既然无缘
    2020-11-30 10:35

    This code might help you.

    #include 
    #include 
    
    using namespace std;
    
    int main() {
       // current date/time based on current system
       time_t now = time(0);
       
       // convert now to string form
       char* dt = ctime(&now);
    
       cout << "The local date and time is: " << dt << endl;
    
       // convert now to tm struct for UTC
       tm *gmtm = gmtime(&now);
       dt = asctime(gmtm);
       cout << "The UTC date and time is:"<< dt << endl;
    }
    

提交回复
热议问题