首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >linux获取本地时间localtime

linux获取本地时间localtime

作者头像
用户7886150
修改2021-02-18 10:39:20
修改2021-02-18 10:39:20
5.2K0
举报
文章被收录于专栏:bit哲学院bit哲学院

参考链接: C++ localtime()

使用c函数库localtime. 头文件<time.h> 

struct tm *localtime(const time_t *timer)

返回值 

struct tm {

   int tm_sec;         /* 秒,范围从 0 到 59                */

   int tm_min;         /* 分,范围从 0 到 59                */

   int tm_hour;        /* 小时,范围从 0 到 23                */

   int tm_mday;        /* 一月中的第几天,范围从 1 到 31                    */

   int tm_mon;         /* 月份,范围从 0 到 11                */

   int tm_year;        /* 自 1900 起的年数                */

   int tm_wday;        /* 一周中的第几天,范围从 0 到 6                */

   int tm_yday;        /* 一年中的第几天,范围从 0 到 365                    */

   int tm_isdst;       /* 夏令时                        */    

};

具体代码: 

#include<iostream>

#include<time.h>

using namespace std;

int main()

{

    time_t rawtime;

    struct tm *info;

    char buffer[80];

    time( &rawtime );

    info = localtime( &rawtime );

    cout<<"current time is:" << asctime(info) << endl;

    cout << "year is: " << info->tm_year+1900 << endl;

    cout << "month is: " << info->tm_mon+1 << endl;

    cout << "day is: " << info->tm_mday << endl;

    cout << "hour is: " << info->tm_hour << endl;

    cout << "min is: " << info->tm_min << endl;

}

执行结果: current time is Fri May 8 11:17:26 2020 

year is: 2020 month is: 5 day is: 8 hour is: 11 min is: 17

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系转载前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档