加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

linux 中system time函数

(2010-09-03 15:44:52)
标签:

linux

函数

杂谈

分类: it工作

system函数 是执行Shell命令

例如

#include<stdio.h>

#include<stdlib.h>

int main()

{

   system("ls");

   return 0;

}

time(&t) 函数是取得当前的时间 存放在他的参数指针中

localtime(&t)将秒数转换成当地目前的时间和日期

例如:

#include<stdio.h>

#include<time.h>

int main(int argc,char **argv)

{

   time_t t;

   struct tm *tm;

   time(&t);

   tm=localtime(&t);

   printf("%02d:%02d:%02d      $04d.%02d.%02d\n",tm->tm_hour,tm->tm_min,tm->tm_sec,tm->tm_year-100+2000,tm->tm_mon+1,tm->tm_mday);

}

其中结构体struct tm定义如下

struct tm

{

  int tm_sec;//代表目前秒数,正常范围为0-59,但允许至61秒

  int tm_min;//代表目前分数,范围0-59

  int tm_hour;//从午夜算起的时数,范围为0-23

  int tm_mday;//目前月份的日数,范围01-31

  int tm_mon;//代表目前月份,从一月算起,范围0-11

  int tm_year;//从1900年算起至今的年数

  int tm_wday;//一星期的日数,从星期一算起,范围0-6

  int tm_yday;//从今年1月1日算起至今的天数,范围为0-365

  int tm_isdst;//日光节约时间的旗标

};

localtime()函数返回的时间日期已经转换成当地的时区

 

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有