获得linux的系统时间

 time_t tNow;
 char buf[30] = {0};
    struct tm *pTime;
    time(&tNow);
    pTime=localtime(&tNow); //取得当地时间
   
    //下面2种方法都可以
    strftime(buf,sizeof(buf),"%Y-%m-%d %H:%M:%S",pTime);
    /*sprintf(buf,"%d-%02d-%02d %02d:%02d:%02d" ,
                 (1900+pTime -> tm_year),
                 (pTime -> tm_mon +1),
                 pTime -> tm_mday,
                 pTime -> tm_hour,
                 pTime -> tm_min,
                 pTime->tm_sec);*/
   
    printf("==>%s<==\n",buf);
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页