网站首页 > 基础教程 正文
声明:char *ctime(const time_t *timer)
timer:这是指向time_t对象的指针,该对象包含一个日历时间
#include<stdio.h>
#include<time.h>
int main(){
time_t curtime;//定义对象curtime;
time(&curtime);//用time函数将对象curtime转换指针
printf("当前时间=%s",ctime(&curtime));//返回当前时间
return 0;
}
ctime不安全函数:
errno_t ctime_s(char *buffer,rsize_t bufsz,const time_t *time)
#include<stdio.h>
#include<time.h>
int main(){
time_t curtime=time(null);
char str[26];
ctime_s(str,sizeof str,&curtime);//对象,变量字节大小,指针对象。
printf(str);
}
int main(void) {
time_t now = time(0);
char str[26];
ctime_s(str, sizeof str, &now);
cout << str << endl;
cout << now << endl;
struct tm tml;
localtime_s(&tml,&now);
cout << "年:" << tml.tm_year+1900 << endl;
cout << "月:" << tml.tm_mon+1<< endl;
cout << "日:" << tml.tm_mday << endl;
cout << "时间:" << tml.tm_hour << ":" << tml.tm_min << ":" << tml.tm_sec << endl;
cout << tml.tm_wday << endl;
cout << tml.tm_yday+1 << endl;
system("pause");
return 0;
}
猜你喜欢
- 2024-10-19 Python3 datetime模块指南:日期时间操作、时区管理与实战案例
- 2024-10-19 C++及数据结构复习笔记,类和对象很简单?为啥好多程序员还不会
- 2024-10-19 Linux时间和日期 linux 时间 表示方法
- 2024-10-19 C/C++的8种时间度量方式以及代码片段
- 2024-10-19 Python实战:使用 datetime模块处理时间日期的全方位指南
- 2024-10-19 C++编程的 42 条建议(四) c++编程100例
- 2024-10-19 mount with noatime - 合理关闭atime提高服务器性能
- 2024-10-19 linux下连续三次fork()——深度理解进程创建函数
- 2024-10-19 C函数time和clock的计时区别 c计时器函数
- 2024-10-19 win进程弹出Microsoft Visual C++ Runtime Library的解决办法
- 最近发表
- 标签列表
-
- gitpush (61)
- pythonif (68)
- location.href (57)
- tail-f (57)
- pythonifelse (59)
- deletesql (62)
- c++模板 (62)
- css3动画 (57)
- c#event (59)
- linuxgzip (68)
- 字符串连接 (73)
- nginx配置文件详解 (61)
- html标签 (69)
- c++初始化列表 (64)
- exec命令 (59)
- canvasfilltext (58)
- mysqlinnodbmyisam区别 (63)
- arraylistadd (66)
- node教程 (59)
- console.table (62)
- c++time_t (58)
- phpcookie (58)
- mysqldatesub函数 (63)
- window10java环境变量设置 (66)
- c++虚函数和纯虚函数的区别 (66)