加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C语言 strftime 格式化显示日期时间的实现

发布时间:2020-12-16 05:15:35 所属栏目:百科 来源:网络整理
导读:C/C++程序中需要程序显示当前时间,可以使用标准函数strftime。 函数原型: size_t strftime (char* ptr,size_t maxsize,const char* format, const struct tm* timeptr ); 代码示例: #include stdio.h#include time.hint main (){ time_t rawtime; struct

C/C++程序中需要程序显示当前时间,可以使用标准函数strftime。

函数原型:size_t strftime (char* ptr,size_t maxsize,const char* format,const struct tm* timeptr );

代码示例:

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

int main ()
{
  time_t rawtime;
  struct tm * timeinfo;
  char buffer [128];

  time (&rawtime);
  timeinfo = localtime (&rawtime);

  strftime (buffer,sizeof(buffer),"Now is %Y/%m/%d %H:%M:%S",timeinfo);
  puts (buffer);

  return 0;
}

代码输出:

格式化时间说明表:

 

以上这篇C语言 strftime 格式化显示日期时间的实现就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持编程小技巧。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读