关于时间
来源:互联网 发布:php 判断是微信浏览器 编辑:程序博客网 时间:2024/05/22 13:38
<span style="background-color: rgb(255, 255, 255); font-family: Arial; font-size: 14px; line-height: 26px;">转载:http://blog.csdn.net/shandianling/article/details/7707925</span>
<span style="background-color: rgb(255, 255, 255); font-family: Arial; font-size: 14px; line-height: 26px;">1)求 时间差(精确到微秒) </span><span style="background-color: rgb(255, 255, 255); font-family: Arial; font-size: 14px; line-height: 26px;">int gettimeofday (struct timeval *__restrict __tv,__timezone_ptr_t __tz);</span>
<pre name="code" class="cpp">#include <stdio.h>#include <sys/time.h>intmain(void){ int i=0; struct timeval tv,tv2; gettimeofday(&tv, NULL); for (i = 0; i < 100000; i++) { printf("%d\t",i+1); if((i+1)%20 == 0) puts("\n"); } gettimeofday(&tv2, NULL); printf("\nsecond : %f", (tv2.tv_usec - tv.tv_usec)/1000000.0 + (tv2.tv_sec-tv.tv_sec) ); return 0;}
2)求当前时间(精确到秒) time(0) 及时间的转换。
<span style="font-family: Arial; font-size: 14px; line-height: 26px;"></span><pre name="code" class="cpp">#include <time.h>#include <stdio.h>#include <string.h>intmain(){ time_t now = time(0); const char * cnow = ctime(&now); struct tm *ptmNow = localtime(&now); char ctmnow[128] = { 0 }; printf("秒数:%d\n",now); printf("原始时间:%s",cnow); sprintf(ctmnow, "%4d-%02d-%02d %02d:%02d:%02d", 1900 + ptmNow->tm_year, 1+ptmNow->tm_mon,ptmNow->tm_mday,ptmNow->tm_hour,ptmNow->tm_min,ptmNow->tm_sec); printf("手动转换为日期: %s\n",ctmnow); strftime(ctmnow,sizeof(ctmnow),"自动转换的日期: %Y-%m-%d %H:%M:%S",ptmNow); //格式化时间//strftime(ctmnow,sizeof(ctmnow),"自动转换的日期: %F %T",ptmNow); //或格式化时间 printf("%s\n",ctmnow); return 0;}
<span style="font-family: Arial; font-size: 14px; line-height: 26px;"></span>3)时间函数相互关系
<span style="font-family: Arial; font-size: 14px; line-height: 26px;"><img src="file:///c:/documents and settings/administrator/application data/360se6/User Data/temp/1341373996_2710.jpg" alt="" /><img src="http://img.blog.csdn.net/20150813164231066?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" /></span>
0 0
- 关于时间
- 关于时间
- 关于时间
- 关于时间
- 关于时间
- 关于时间
- 关于时间
- 关于时间
- 关于时间
- 关于时间
- 关于时间
- 关于时间戳转时间
- 关于建立时间,保持时间,传输时间
- MS SQL关于时间
- 关于时间函数
- 关于时间的记忆
- 关于时间的诗词
- 关于时间的悖论
- Redis 数据持久化
- python快速使用(二)python面向过程编程
- intellij idea 简单使用教程
- 单链表逆序:通过递归和循环实现。
- acid(数据库事务正确执行的四个基本要素的缩写)
- 关于时间
- 存贮beatbox
- 链式队列的C++实现
- CMAKE的使用
- 如何修改MFC界面风格
- 【bzoj2083】 POI2010Intelligence test 乱搞
- Agri-Net 1258
- 【bzoj1003】【ZJOI2006】【物流运输】【dp+最短路】
- SQLServer 可更新订阅数据在线架构更改(增加字段)方案