zoukankan      html  css  js  c++  java
  • c++获取时间戳

    #include <iostream>
    #include <string>
    #include <time.h>
    using namespace std;
    
    struct NowDate
    {
        char tmp0[16]; //年月日
        char tmp1[16]; //时分秒
        char tmp2[4];  //毫秒
    };
    
    NowDate getTime()
    {
        time_t timep;
        time (&timep);
        NowDate date;
    
        strftime(date.tmp0, sizeof(date.tmp0), "%Y-%m-%d",localtime(&timep) );
        strftime(date.tmp1, sizeof(date.tmp1), "%H:%M:%S",localtime(&timep) );
    
        struct timeb tb;
        ftime(&tb);     
        sprintf(date.tmp2,"%d",tb.millitm);
    
        return date;
    }
    
    int main()
    {
        NowDate time = getTime();
        cout << time.tmp0 <<endl;
        cout << time.tmp1 <<endl;
        cout << time.tmp2 <<endl;
    
        return 0;
    }
  • 相关阅读:
    【设计模式
    【JavaEE】之SSM入门项目的搭建
    【Android
    【Android
    【Android
    【Android
    【Android
    【Android
    随风 随意
    优秀代码所具备的品质
  • 原文地址:https://www.cnblogs.com/hjj-fighting/p/10834131.html
Copyright © 2011-2022 走看看