C++ 中的asctime() 函数将结构体 tm 的给定日历时间转换为字符表示。
asctime() 函数在<ctime> 头文件中定义。
asctime()原型
char* asctime(const struct tm * time_ptr);
asctime() 函数将指向 tm 对象的指针作为其参数,并返回给定日历时间的文本表示形式:
Www Mmm dd hh:mm:ss yyyy
| 
 类型  | 
 说明  | 
 从...获取  | 
 值  | 
|---|---|---|---|
| 
 Www  | 
 3 个字母的星期几  | 
 
  | 
 周一至周日  | 
| 
 Mmm  | 
 3 个字母的月份名称  | 
 
  | 
 一月至十二月  | 
| 
 dd  | 
 2 位数的月份日期  | 
 
  | 
 00 至 31  | 
| 
 hh  | 
 2 位数小时  | 
 
  | 
 00 至 23  | 
| 
 mm  | 
 2 位数分钟  | 
 
  | 
 00 至 59  | 
| 
 ss  | 
 2 位数秒  | 
 
  | 
 00 至 59  | 
| 
 yyyy  | 
 4 位数年份  | 
 
  | 
 4位数字  | 
参数:
time_ptr:指向要转换的 tm 对象的指针。
返回:
- 指向空终止字符串的指针,指向给定时间的字符表示。
 
示例:asctime() 函数如何工作?
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
	time_t curr_time;
	time(&curr_time);
	cout << "Current date and time: " << asctime(localtime(&curr_time));
	return 0;
}
运行程序时,输出将是:
Current date and time: Tue Mar 21 13:52:57 2017
相关用法
- C++ asctime()用法及代码示例
 - C++ asinh()用法及代码示例
 - C++ complex asinh()用法及代码示例
 - C++ complex asin()用法及代码示例
 - C++ asin()用法及代码示例
 - C++ atexit()用法及代码示例
 - C++ any_of()用法及代码示例
 - C++ atof()用法及代码示例
 - C++ abort()用法及代码示例
 - C++ atol()用法及代码示例
 - C++ complex acosh()用法及代码示例
 - C++ array at()用法及代码示例
 - C++ array::fill()、array::swap()用法及代码示例
 - C++ atoll()用法及代码示例
 - C++ array::size()用法及代码示例
 - C++ array::rbegin()、array::rend()用法及代码示例
 - C++ atan()用法及代码示例
 - C++ complex abs()用法及代码示例
 - C++ array::front()、array::back()用法及代码示例
 - C++ array::front()用法及代码示例
 
注:本文由纯净天空筛选整理自 C++ asctime()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
