时间函数与时间转换

和时间函数相关的类型:

typedef long time_t;

 

struct tm {

  int tm_sec;   /* Seconds 秒*/

  int tm_min;   /* Minutes 分*/

  int tm_hour;  /* Hour (0--23) 小时*/

  int tm_mday;  /* Day of month (1--31) 日期*/

  int tm_mon;   /* Month (0--11) 月份,此处一定要注意取值范围是0-11*/

  int tm_year;  /* Year (calendar year minus 1900) 在C++ Builder中计算基数是1900年开始,因此需要用年减去1900*/

  int tm_wday;  /* Weekday (0--6; Sunday = 0) 星期*/

  int tm_yday;  /* Day of year (0--365) 一年中的第几天*/

  int tm_isdst; /* 0 if daylight savings time is not in effect) 调整参数*/

}; 

 

C++ 中的时间转换函数小结:

1. time_t mktime(struct tm *t);

函数功能:将tm结构体中给出的时间转换为time_t类型的时间,需要构造时间结构体tm,time_t的可表示范围为 Jan 1 1970 00:00:00 to Jan 19 2038 03:14:07.

 

2.struct tm *localtime(const time_t *timer);

函数功能:该函数功能与1相反。

 

3.struct tm *gmtime(const time_t *timer);

函数功能:将日历时间转换为Greenwich时间。

 

4.time_t time(time_t *timer);

函数功能:入参为NULL时返回系统时间。since 00:00:00 GMT, January 1, 1970

入参不为NULL时返回系统时间并保存在由timer指定的位置。

 

 

将时间转换为时间字符串:

 

将时间字符串转换为时间:

 

C++ builder中与时间相关的组件的使用:

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值