• Linux获取系统当前时间(精确到毫秒)


    #include <stdio.h>
    #include <time.h>
    #include <sys/time.h>
    
    void sysLocalTime(void)
    {
        time_t timesec;
        struct tm *t;    
        
        time(&timesec);
        t = localtime(&timesec);
        
        printf("%d-%d-%d %d:%d:%d
    ", 1900+t->tm_year, 1+t->tm_mon, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);    
    }
    
    void sysUsecTime(void)
    {
        struct timeval tv;
        struct timezone tz;    
        struct tm *t;
        
        gettimeofday(&tv, &tz);
        printf("tv_sec:%ld
    ",tv.tv_sec);
        printf("tv_usec:%ld
    ",tv.tv_usec);
        printf("tz_minuteswest:%d
    ",tz.tz_minuteswest);
        printf("tz_dsttime:%d
    ",tz.tz_dsttime);
        
        t = localtime(&tv.tv_sec);
        printf("time_now:%d-%d-%d %d:%d:%d.%ld
    ", 1900+t->tm_year, 1+t->tm_mon, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, tv.tv_usec);
    }
    
    int main(void)
    {
        sysLocalTime();    
        sysUsecTime();
        
        return 0;
    }
    

      

  • 相关阅读:
    ansible-handlers
    LNMP
    编译安装sshpass
    cadence-irun(xrun) 增量编译
    sva 基础语法
    bsub && lsf 介绍
    Perl 输出内容到 excel
    Perl sendmail
    dlopen与dlsym用法
    perl在linux下通过date获取当前时间
  • 原文地址:https://www.cnblogs.com/chars/p/4975460.html
Copyright © 2020-2023  润新知