您的位置:首页 > 运维架构 > Linux

linux下时间编程

2011-07-19 11:52 253 查看
/*
* =====================================================================================
*
*       Filename:  time.c
*
*    Description:
*
*        Version:  1.0
*        Created:  2011年07月19日 10时38分20秒
*       Revision:  none
*       Compiler:  gcc
*
*         Author:  sunsea (zsx), sunsea1026@gmail.com
*        Company:
*
* =====================================================================================
*/

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

int main(int argc, char* argv[])
{
time_t	tv;
struct	tm *lc_time;
char	time_str[128];

/* 获取时间,以格林尼治时间(GMT)为标准,
* 从1970年1月1日00:00:00到现在的此时此刻所经过的秒数。*/
tv = time(NULL);

/* 把从1970-1-1零点零分到当前时间系统所偏移的秒数时间转换为日历时间。 */
lc_time = localtime(&tv);

/* asctime(),转换日期和时间为ASCII码 */
memset(time_str, 0, sizeof(time_str));
strcpy(time_str, asctime(lc_time));

printf("%s", time_str);

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: