C 库函数 - ctime()

C++ 教程 · 2019-02-25 21:28:46

描述

C 库函数 char *ctime(const time_t *timer) 返回一个表示当地时间的字符串,当地时间是基于参数 timer

返回的字符串格式如下: Www Mmm dd hh:mm:ss yyyy 其中,Www 表示星期几,Mmm 是以字母表示的月份,dd 表示一月中的第几天,hh:mm:ss 表示时间,yyyy 表示年份。

声明

下面是 ctime() 函数的声明。

char *ctime(const time_t *timer)

参数

  • timer -- 这是指向 time_t 对象的指针,该对象包含了一个日历时间。

返回值

该函数返回一个 C 字符串,该字符串包含了可读格式的日期和时间信息。

实例

下面的实例演示了 ctime() 函数的用法。

实例

#include <stdio.h> #include <time.h> int main () { time_t curtime; time(&curtime); printf("当前时间 = %s", ctime(&curtime)); return(0); }

让我们编译并运行上面的程序,这将产生以下结果:

当前时间 = Mon Aug 13 08:23:14 2012

点击查看所有 C++ 教程 文章: https://codercto.com/courses/l/18.html

查看所有标签

Smarter Than You Think

Smarter Than You Think

Clive Thompson / Penguin Press HC, The / 2013-9-12 / USD 27.95

It's undeniable—technology is changing the way we think. But is it for the better? Amid a chorus of doomsayers, Clive Thompson delivers a resounding "yes." The Internet age has produced a radical new ......一起来看看 《Smarter Than You Think》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码