zoukankan      html  css  js  c++  java
  • C语言获取系统当前时间

    C语言获取系统当前时间

    time_t -- 时间类型

    struct tm -- 时间结构

     time(&now)函数获取当前时间距1970年1月1日的秒数,以秒计数单位。

    localtime ( &rawtime ); -- 转为当地时间,tm 时间结构 

    比如获取当前年份:
            int iyear = 0;
            int sysyear = 0;
            time_t now;
            struct tm *timenow;
            time(&now);
            timenow = localtime(&now);
            sysyear = timenow->tm_year+1900;
    例子:获取系统当前时间

    #include<stdio.h>
    #include<time.h>
    int main (void)
    {
        int sysyear = 0;
        int sysmonth=0;
        int sysday=0;
        time_t now;
        struct tm *timenow;
        time(&now);
        timenow = localtime(&now);
        sysyear = timenow->tm_year+1900;
        sysmonth=timenow->tm_mon+1;
        sysday=timenow->tm_mday;
        printf("系统当前时间:%d-%d-%d ",sysyear,sysmonth,sysday);
        return 0;
    }

  • 相关阅读:
    poj1087最大流拆点
    3月15上午的函数练习
    3月15
    3月13上午
    3月13
    3月12
    break语句
    3月11
    3月10号
    3月9号
  • 原文地址:https://www.cnblogs.com/pangblog/p/3400373.html
Copyright © 2011-2022 走看看