localtime 返回指向当前时间的指针

头文件

#include <time.h>

语法

struct tm *localtime( const time_t *time );

功能

函数返回本地日历时间。

示例

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

int main(void)
{
    time_t timer;
    struct tm *tblock;

    /* gets time of day */
    timer = time(NULL);

    /* converts date/time to a structure */
    tblock = localtime(&timer);

    printf("Local time is: %s", asctime(tblock));

    return 0;
}

输出结果:

Local time is: Thu Jul 14 23:21:52 2022
关于
本网站属于个人的非赢利性网站,转载的文章遵循原作者的版权声明,如果原文没有版权声明,请来信告知:hxstrive@outlook.com
公众号