Chinaunix首页 | 论坛 | 博客
  • 博客访问: 156546
  • 博文数量: 19
  • 博客积分: 901
  • 博客等级: 准尉
  • 技术积分: 268
  • 用 户 组: 普通用户
  • 注册时间: 2010-01-14 23:58
文章分类

全部博文(19)

文章存档

2010年(19)

我的朋友

分类: C/C++

2010-05-17 15:10:48

The meaning of each is:
MemberMeaningRange
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
下面程序计算美国凤凰城 (-7),中国北京(+8),和冰岛(0)时间:
#include
#include  
struct {
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;
void show(struct tm * timeinfo,int j)
{
 int day,hour;
 if(j>0)
 {
if((j+timeinfo->tm_hour)/24==1)
 day=timeinfo->tm_mday+1;
else
 day=timeinfo->tm_mday;
 hour=(j+timeinfo->tm_hour)%24;
 }
 if(j==0)
 {
 day=timeinfo->tm_mday;
 hour=(j+timeinfo->tm_hour)%24;
 }
 if(j<0)
 {
if((j+timeinfo->tm_hour)/24<0)
 day=timeinfo->tm_mday-1;
else
 day=timeinfo->tm_mday;
 hour=(j+timeinfo->tm_hour)%24;
 }
 printf ( "%4d-%02d-%02d %02d:%02d:%02d\n",1900+timeinfo->tm_year, 1+timeinfo->tm_mon,
day,hour,timeinfo->tm_min,timeinfo->tm_sec);
}
void main ()
{
time_t timer;
struct tm * timeinfo,*ptm;
time ( &timer );//Pointer to an object of type time_t, where the time value is stored.
timeinfo = localtime ( &timer);//返回当地时区时间
ptm = gmtime ( &timer );//返回格林制时区时间
printf("按格式显示冰岛时间\n");
show(ptm,0);
printf("按格式显示美国凤凰城时间\n");
show(ptm,-7);
printf("按格式显示中国北京时 间\n");
show(ptm,8);
}
按格式显示冰岛时间
2009-09-24 19:26:30
按格式显 示美国凤凰城时间
2009-09-24 12:26:30
按格式显示中国北京时间
2009-09-25 03:26:30 ......
阅读(6712) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~