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 []; time (&rawtime);
printf("%ld\n", rawtime); timeinfo = localtime (&rawtime);
strftime (buffer,sizeof(buffer),"Now is %Y/%m/%d %H:%M:%S",timeinfo);
printf("%s\n", buffer); return ;
}

代码输出:

格式化时间说明表:

更多资源见如下链接:

cplusplus strftime:http://www.cplusplus.com/reference/ctime/strftime/?kw=strftime

http://www.cnblogs.com/Wiseman/archive/2005/10/24/260576.html

C语言 strftime 格式化显示日期时间 时间戳的更多相关文章

  1. LaTeX去掉默认显示日期时间

    LaTeX去掉默认显示日期时间: \date{}

  2. 在Jquery里格式化Date日期时间数据

    在Jquery里格式化Date日期时间数据: $(function(){ //当前时间格式化yyyy-MM-dd HH:mm:ss alert(timeStamp2String(new Date(). ...

  3. JAVA中String.format的用法 格式化字符串,格式化数字,日期时间格式化,

    1.对整数进行格式化:%[index$][标识][最小宽度]转换方式        我们可以看到,格式化字符串由4部分组成,其中%[index$]的含义我们上面已经讲过,[最小宽度]的含义也很好理解, ...

  4. 使用Python将字符串转换为格式化的日期时间字符串

    我正在尝试将字符串“20091229050936”转换为“2009年12月29日(UTC)” >>>import time >>>s = time.strptime ...

  5. 软件素材---C/C++格式化显示当前时间--标准函数strftime

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

  6. C语言字符串格式化显示

    符号                  作用 ──────────────────────────     %d              十进制有符号整数     %i              输 ...

  7. js显示日期时间(集锦)

    1.最简单的时钟显示 <div id="time"></div> <script> setInterval(); </script>

  8. DATE_FORMAT() 函数用于以不同的格式显示日期/时间数据。

    DATE_FORMAT(date,format) format参数的格式有 %a 缩写星期名 %b 缩写月名 %c 月,数值 %D 带有英文前缀的月中的天 %d 月的天,数值(00-31) %e 月的 ...

  9. IntelliJ IDEA调试时,格式化显示日期变量

    格式化前: 格式化后: new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(this); 入门常用知识: Ct ...

随机推荐

  1. 解决命令行运行python文件,出现No module named *** 报错问题

    有时候在一个项目中运行的时候,可能是之前已经mark成sources root 你自己忘记了, 于是就在命令行也执行python文件,然后就出现 No module named *** 等 相关你认为 ...

  2. 四、django rest_framework源码之频率控制剖析

    1 绪言 权限判定之后的下一个环节是访问频率控制,本篇我们分析访问频率控制部分源码. 2 源码分析 访问频率控制在dispatch方法中的initial方法调用check_throttles方法开始. ...

  3. Jquery的方法(二)

    一.文档操作1.html()和text()的区别 <div id="J_div"><b><i>我是谁</i></b>&l ...

  4. Python下读取转换unicode的json格式

    转自: https://blog.csdn.net/felcon/article/details/38524317 JSON(JavaScript Object Notation) 是一种轻量级的数据 ...

  5. BZOJ 1283 序列 费用流 网络流 线性规划

    https://darkbzoj.cf/problem/1283 给出一个长度为N的正整数序列Ci,求一个子序列,使得原序列中任意长度为M的子串中被选出的元素不超过K(K,M<=100) 个,并 ...

  6. BZOJ.2916.[POI1997]Monochromatic Triangles(三元环)

    题目链接 \(Description\) n个点的完全图,其中有m条边用红边相连,其余边为蓝色.求其中三边同色的三角形个数. \(Solution\) 直接求同色 除了n^3 不会.. 三角形总数是C ...

  7. Codecademy python

    #1 print "Welcome to Python!" #2 my_variable = #3 # Set the variables to the values listed ...

  8. JavaScript中的callee与caller的区别

    1.callee callee是对象的一个属性,该属性是一个指针,指向参数arguments对象的函数 作用:就是用来指向当前对象 返回正被执行的 Function 对象,也就是所指定的 Functi ...

  9. Qt线程外使用Sleep

    一:方法1 QTime t; t.start(); while(t.elapsed()<1000){     QCoreApplication::processEvents();} 二:方法2 ...

  10. angularjs-ui插件ui-select和html的select注意事项及区别

    项目中使用了angular-ui里的ui-select指令,地址https://github.com/angular-ui/ui-select 1. ng-model没有双向数据绑定 最开始没有看手册 ...