C时间函数集 (转贴)
C语言的标准库函数包括一系列日期和时间处理函数,它们都在头文件中说明。下面列出了这些函数。在头文件中定义了三种类型:time_t,struct tm和clock_t。
在中说明的C语言时间函数
time_t time(time_t *timer);
double difftime(time_t time1,time_t time2);
struct tm *gmtime(const time_t *timer);
struct tm *localtime(const time_t *timer);
char *asctime(const struct tm *timeptr);
char *ctime(const time_t *timer);
size_t strftime(char *s,size_t maxsize,const char *format,const struct tm *timeptr);
time_t mktime(struct tm *timeptr);
clock_t clock(void);
下面是我从网上收集到的时间函数集
asctime(将时间和日期以字符串格式表示)
相关函数
time,ctime,gmtime,localtime
表头文件
#include
定义函数
char * asctime(const struct tm * timeptr);
函数说明
asctime()将参数timeptr所指的tm结构中的信息转换成真实世界所使用的时间日期表示方法,然后将结果以字符串形态返回。此函数已经由时区转换成当地时间,字符串格式为:"Wed Jun 30 21:49:08 1993\n"
返回值
若再调用相关的时间日期函数,此字符串可能会被破坏。此函数与ctime不同处在于传入的参数是不同的结构。
附加说明
返回一字符串表示目前当地的时间日期。
范例
#include
main()
{
time_t timep;
time (&timep);
printf("%s",asctime(gmtime(&timep)));
}
执行
Sat Oct 28 02:10:06 2000
ctime(将时间和日期以字符串格式表示)
相关函数
time,asctime,gmtime,localtime
表头文件
#include
定义函数
char *ctime(const time_t *timep);
函数说明
ctime()将参数timep所指的time_t结构中的信息转换
相关文档:
计算线程执行某项任务消耗的时间时,许多开发人员会调用GetTickCount/GetTickCount64编写如下的代码:
// Get the current time (start time)
ULONGLONG qwStartTime = GetTickCount64();
// Perform complex algorithm here
// Subtract start time from current time to get duration
ULONGLONG dwElapsedTime = Get ......
张孝祥
另外,在实际的VC++教学中,发现很少有真正精通了C语言编程的学员,一般都有或多或少概念不是完全清楚的问题,特别是一些需要丰富的实战经验才能体会和明白的问题,如字符串,指针,类型转换,定义指向函数的指针类型,这也是导致学习VC++困难的一个原因。下面有 ......
// 方案— 优点:仅使用C 标准库;缺点:只能精确到秒级
#include <time.h>
#include <stdio.h>
int main( void )
{
time_t t = time(0);
char tmp[64];
strftime( tmp, sizeof(tmp), "%Y/%m/%d %X %A 本年第%j天 %z",localtim ......
7.2.1 介绍getchar()和putchar()
前面的多数程序所输入的内容都是数字。为了练习使用其他的形式,让我们来看一个面向字符的例子。
现在我们将接触专门为面向字符I/O而设计的一对C函数:getchar()和putchar()。
.
getchar()函数没有参数,它返回来自输入设备的下一个字符。例如,下面的语句读取下一个输入字符并将它的值 ......
以下是我的测试oci的例子!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "oci.h"
static OCIServer *srvhp;
static OCISession *p_session;
static OCIEnv &nb ......