C语言时间与日期函数初学

  1. 日期和时间转换函数 asctime
函数原型:char * asctime(const struct tm *tblock)

#include<stdio.h>
#include<string.h>
#include<time.h>
int main(void)
{
    struct tm t;
    char str[60];
    // 下面设置结构体 t 的 时间成员变量
    t.tm_sec = 1;//设置当前的秒
    t.tm_min = 30;// 设置当前分钟
    t.tm_hour = 9;// 设置当前 时
    t.tm_mday = 22;// 设置 日
    t.tm_mon = 11; // 月
    t.tm_year = 56; /*年 这儿可以只写 56 而不必 写 1956  大部分情况下,系统会默认 但你写的的时间 大于某一时间时 就会 在前面加 19 ,有时候 比如 写的 是 03 他就会是 2003*/
    strcpy(str, asctime(&t));// 将asctime 函数转换过来的 字符串复制到字符数组 str 中
    printf("%s\n",str);

}
  1. 测定运行时间的函数
函数原型: clock_t clock(void);
功能: 确定所用的处理器时间,也就是在运行时获得当前处理器时间
例:
    #include<stdio.h>
    #include<time.h>
    #include<dos.h>
    int main(void)
    {
        clock_t start, end;
        start = clock(); // 取得 延迟开始时间
        delay(3000);// 使用延迟函数延迟 3000 毫秒 = 3秒
        end = clock();//取的延时完后的时间
        printf("The time was %f \n",(end - start) / CLK_TCK);// CLK_TCK 为 时间转化常量 除以其后 可得到以秒为单位的时间
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值