码迷,mamicode.com
首页 > 系统相关 > 详细

Linux系统编程(时间和日期)

时间:2015-08-29 06:22:51      阅读:272      评论:0      收藏:0      [点我收藏+]

标签:linux   编程   

#include <time.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

int main(void)
{
	int i;
	time_t the_time;
	
	for(i = 1; i<= 10; i++)
	{
		the_time = time((time_t *)0);
		printf("The time is %ld\n", the_time);
		sleep(2);

	}
	exit(0);
}

执行的结果:

技术分享

#include <time.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
	struct tm *tm_ptr;
	time_t the_time;
	(void)time(&the_time);
	tm_ptr = gmtime(&the_time);

	printf("Raw time is %ld\n",the_time);
	printf("gmtime gives:\n");
	printf("data:%02d/%02d/%02d\n",tm_ptr->tm_year,tm_ptr->tm_mon+1,tm_ptr->tm_mday);

	printf("time:%02d/%02d/%02d\n",tm_ptr->tm_hour,tm_ptr->tm_min,tm_ptr->tm_sec);
	exit(0);
}
技术分享

版权声明:本文为博主原创文章,未经博主允许不得转载。

Linux系统编程(时间和日期)

标签:linux   编程   

原文地址:http://blog.csdn.net/u011046042/article/details/48070483

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!