源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

C语言中将日期和时间以字符串格式输出的方法

  • 时间:2022-01-25 11:39 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:C语言中将日期和时间以字符串格式输出的方法
[b]ctime()函数: [/b]头文件:
#include <time.h>
定义函数:
char *ctime(const time_t *timep);
函数说明:ctime()将参数timep 所指的time_t 结构中的信息转换成真实世界所使用的时间日期表示方法,然后将结果以字符串形态返回。此函数已经由时区转换成当地时间,字符串格式为"Wed Jun 30 21 :49 :08 1993\n"。 注意:若再调用相关的时间日期函数,此字符串可能会被破坏。 返回值:返回一字符串表示目前当地的时间日期。 范例
#include <time.h>
main(){
  time_t timep;
  time (&timep);
  printf("%s", ctime(&timep));
}
执行
Sat Oct 28 10 : 12 : 05 2000
[b]asctime()函数: [/b] 头文件:
#include <time.h>
定义函数:
char *asctime(const struct tm * timeptr);
函数说明:asctime()将参数timeptr 所指的tm 结构中的信息转换成真实世界所使用的时间日期表示方法,然后将结果以字符串形态返回。此函数已经由时区转换成当地时间,字符串格式为:"Wed Jun 30 21:49:08 1993\n" 返回值:若再调用相关的时间日期函数,此字符串可能会被破坏。此函数与ctime 不同处在于传入的参数是不同的结构。 附加说明:返回一字符串表示目前当地的时间日期. 范例
#include <time.h>
main(){
  time_t timep;
  time (&timep);
  printf("%s", asctime(gmtime(&timep)));
}
执行
Sat Oct 28 02:10:06 2000
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部