C/C++中关于时间的函数 localtime()

函数:struct tm * localtime ( const time_t * timer );

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

int main()
{
	time_t test;
	test = time(NULL);//抓取现在的时间 ——目前距离1970-01-01-00:00:00所经历的秒数 
	printf("%s\n",ctime(&test));//将上面的秒数转换为人们易读的时间表达方式 ,并在末尾换行 
	printf("local hour:%d\n",localtime(&test)->tm_hour); 
	//localtime的返回值是一个指向tm结构的指针,tm见程序最后注释部分
	//使用asctime()可以讲 tm 结构转换为人们易读的string格式 (同ctime())
	struct tm * ptime; 
	ptime = localtime(&test);
	printf("%s\n",asctime(ptime)); 
	
	return 0;
}
/*
The structure contains nine members of type int, which are (in any order):
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;

tm_sec	seconds after the minute	0-61*
tm_min	minutes after the hour	0-59
tm_hour	hours since midnight	0-23
tm_mday	day of the month	1-31
tm_mon	months since January	0-11
tm_year	years since 1900	
tm_wday	days since Sunday	0-6
tm_yday	days since January 1	0-365
tm_isdst	Daylight Saving Time flag	
*/ 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值