ctime(ctime头文件的作用)
C语言 ctime()
没有 #include 的写法,只有 #include ,time.h 是C语言里时间的库函数。
ctime在C语言里,只是一个把日期和时间转换为字符串的函数。具体函数原型为:
char *ctime( const time_t *timer )
用法实例:
#include
#include
int main( void )
time_t ltime;
time(
printf( "The time is %s\n", ctime(
return 0;
假如当前的系统时间是2011年1月19日,15时16分20秒,星期三,那么经过这段程序运行后,在显示终端上出现:The time is Wed Jan 19 15:16:20 2011asctime是把时间换成ascii码。
ctime是把时间转换成字符串。
具体介绍如下:
函数名: asctime
功 能: 转换日期和时间为ASCII码
用 法: char *asctime(const struct tm *tblock);
程序例:
#include
#include
#include
int main(void)
struct tm t;
char str[80];
/* sample loading of tm structure */
t.tm_sec = 1; /* Seconds */
t.tm_min = 30; /* Minutes */
t.tm_hour = 9; /* Hour */
t.tm_mday = 22; /* Day of the Month */
t.tm_mon = 11; /* Month */
t.tm_year = 56; /* Year - does not include century */
t.tm_wday = 4; /* Day of the week */
t.tm_yday = 0; /* Does not show in asctime */
t.tm_isdst = 0; /* Is Daylight SavTime; does not show in asctime */
/* converts structure to null terminated
string */
strcpy(str, asctime(&t));
printf("%s\n", str);
return 0;
英文详解:
[编辑本段]asctime
Synopsis
#include
char *asctime(const struct tm *timeptr);
Description
The asctime function converts the broken-down time in the structure pointed to by timeptr into a string in the form
Sun Sep 16 01:03:52 1973\n\0
using the equivalent of the following algorithm.
char *asctime(const struct tm *timeptr)
static const char wday_name[7][3] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
static const char mon_name[12][3] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
static char result[26];
sprintf(result, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n",
wday_name[timeptr->tm_wday],
mon_name[timeptr->tm_mon],
timeptr->tm_mday, timeptr->tm_hour,
timeptr->tm_min, timeptr->tm_sec,
1900 + timeptr->tm_year);
return result;
Returns
The asctime function returns a pointer to the string.
Example :
#include
#include
void main(void)
struct tm *newtime;
time_t ltime;
/* Get the time in seconds */
time (
/* convert it to the structure tm */
newtime = localtime(
/* print the local time as a string */
printf("The current time and dat are %s", asctime(newtime));
The current time and dat are Mon Dec 28 12:33:50 1998
ctime
函数名: ctime
功 能: 把日期和时间转换为字符串
用 法: char *ctime(const time_t *time);
程序例:
#include
#include
int main(void)
time_t t;
time(&t);
printf("Today's date and time: %s\n", ctime(&t));
return 0;
求采纳为满意回答。函数: ctime
功 能: 把日期和时间转换为字符串
用 法: char *ctime(const time_t *time);
#include
#include
intmain(void)
time_tt;
t=time(&t);
printf("today'sdateandtime:%s\n",ctime(&t));
return0;
注:若在linux下使用本函数,需要include 头文件就是显示当前的时间。 怎么显示忘了 好像能赋值给一个变量把,
ctime是标准c++的类么
CTime是mfc的类。要使用的话生成控制台的时候选支持mfc就可以直接用了不用包含文件。
没选的话包含alttime.h
或者,你也可以用SYSTEMTIME类型,不需要mfc支持。
SYSTEMTIMECurTime;
GetLocalTime(&CurTime);//获得系统当前时间
///
例子上面不是给了么?最后两行。
你的出错问题是没有 这个文件,因为CTime的定义是在alttime.h里的,要包含的话包含这个文件。ctime::getcurrenttime()不是标准c++中的,ctime只是mfc(微软基础类库)中的一个时间类而已。好像是
出错估计是用发问题,或者头文件丢失
ctime(ctime头文件的作用)相关推荐
- Linux中常用头文件的作用--转
http://blog.sina.com.cn/s/blog_5c93b2ab0100q62k.html 1. Linux中一些头文件的作用: <assert.h>:ANSI C.提供断言 ...
- Linux中常用C/C++一些头文件的作用
2019独角兽企业重金招聘Python工程师标准>>> 1. Linux中一些头文件的作用: <assert.h>:ANSI C.提供断言,assert(表达式) < ...
- CC++——库头文件及其作用
1. 一些头文件的作用: :ANSI C.提供断言,assert(表达式) :GCC.GTK,GNOME的基础库,提供很多有用的函数,如有数据结构操作函数.使用glib只需要包含 :GCC.文件夹操作 ...
- C/C++ 头文件的作用和用法
示例代码编译运行环境:Windows 64bits+VS2017+Debug+Win32. 头文件是 C/C++ 程序不可或缺的组成部分,我们需要了解头文件的作用和相关规范. 1.头文件的作用 C/C ...
- C、c++ .h 头文件的作用
C语言头文件的作用 C语言头文件的作用 最近在工作当中遇到了一点小问题,关于C语言头文件的应用问题,主要还是关于全局变量的定义和声明问题. 学习C语言已经有好几年了,工作使用也近半年了,但是对于这部分 ...
- 详解C语言中头文件的作用
大家好,先做个自我介绍,我是天蓬,欢迎阅读本篇博文. 由于本人理解能力不是很好,阅读他人文章时,常常看得晕头晕脑,这让我很是头疼,我想,世界上一定还有和我一样的人(哈哈,不是说你么笨哦).所以,我将会 ...
- 嵌入式linux头文件,飞凌嵌入式知识汇092期:C工程的组织方式(头文件的功能)以及Linux下常用的头文件的作用...
1.1每个C++/C程序通常分为两个文件.一个文件用于保存程序的声明(declaration),称为头文件.另一个文件用于保存程序的实现(implementation),称为定义(definition ...
- C\C++头文件的作用
头文件的作用有三: 一者,C\C++采用源文件单独编译为object文件,最后有链接器链接object文件成为可执行文件.头文件解决了彼源文件中变量和函数在此源文件中引用. 二者,头文件中的函数接口和 ...
- 头文件的作用,函数的返回值,函数的风格,函数的标准库 字符串常量
头文件的作用 #include 指定的头文件的包含目录 #include "windows.h" 优先从文件所在的目录进行.如果文件没有的话,那么就从指定的头文件的包含,目录里面进 ...
最新文章
- 彻底解决Linux索引节点(inode)占用率高的告警
- 汇编语言--jcxz指令
- P4144 大河的序列
- 【知乎】怎么成为一个优秀的程序员,而不是一个优秀的码农?
- ubuntu7.10安装到3D开启
- C# message简单实现窗口间信息接收与发送
- fastai学习:01_intro Questionnaire
- 163相册密码破解秘诀
- 试题10 最大子阵(枚举)
- Java文件– java.nio.file.Files类
- .net weka ikvm java
- Java内存模型—JMM详解
- 数学建模——主成分分析及spss软件操作
- android计步器报告书,Android精准计步器开发-Dylan计歩
- 5.接口参数过滤(phalapi框架总结)
- 数控编程也是c语言吗,学数控编程需要使用个人电脑吗
- JavaScript 事件(冒泡捕获)处理模型
- 大提顿国家公园美丽风景Mac动态壁纸
- RK3568-ANDROID11-降频DDR
- SOAR+HIDS,增强主机安全防护