LINUX系统编程之日历时间

LINUX中时间有两种:

1)日历时间

2)进程时间

日历时间顾名思义即用来获取日历;

主要涉及到的函数有:

time(time_t*);

stime(time_t*);

tm* gmtime(time_t*);

tm* localtime(time_t*);

char *strftime(tm*);

char *asctime(tm*);

time_t* mktime(tm*);

数据结构如下:

time_t

struct tm{

int tm_sec;

int tm_min;

int tm_hour;

int tm_mday;

int tm_wday;

int tm_yday;

int tm_year;

int tm_isdst;

}

转换关系如下图:

示例代码如下:

struct utsname aname;
int a=uname(&aname);
  1. cout << a;
  2. cout << endl;
  3. cout << aname.sysname<< endl;
  4. cout << aname.machine<< endl;
  5. cout << aname.release<< endl;
  6. cout << aname.version<<endl;
  7. cout << aname.nodename<< endl;
  8. time_t time1;
  9. time_t time2;
  10. time2=time(&time1);
  11. cout << time1 << endl;
  12. cout << time2 << endl;
  13. struct tm *tm1;
  14. tm1=localtime(&time1);
  15. cout << tm1->tm_sec<<endl;
  16. cout << tm1->tm_min<<endl;
  17. cout << tm1->tm_hour<<endl;
  18. cout << tm1->tm_mday<<endl;
  19. cout << tm1->tm_mon<<endl;
  20. cout << tm1->tm_year<<endl;
  21. cout << tm1->tm_wday<<endl;
  22. cout << tm1->tm_yday<<endl;
  23. char *css;
  24. css=asctime(tm1);
  25. cout << css;
  26. size_t size=strftime(css,100,"%Y-%m-%d %H-%M-%S %w",tm1);
  27. cout << size << ":"<<css;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值