asctime()函数在ctime头文件中定义。 asctime()函数将结构tm的给定日历时间转换为字符表示形式,即人类可读形式。
用法:
char* asctime(const struct tm * time_ptr);
参数:此函数接受单个参数time_ptr,即指向要转换的tm对象的指针。
返回值:此函数以“ Www Mmm dd hh:mm:ss yyyy”的形式返回日历时间。
以下示例程序旨在说明C++中的asctime()函数:
例:-
// c++ program to demonstrate 
// example of asctime() function. 
  
#include <bits/stdc++.h> 
using namespace std; 
  
int main() 
{ 
    time_t time_ptr; 
   
    time(&time_ptr); 
    cout << "Current date and time = "
         << asctime(localtime(&time_ptr)); 
  
    return 0; 
}
输出:
Current date and time = Mon Oct 1 10:21:26 2018
相关用法
- C++ log()用法及代码示例
 - C++ div()用法及代码示例
 - C++ fma()用法及代码示例
 - C++ fread()用法及代码示例
 - C++ atexit()用法及代码示例
 - C++ gmtime()用法及代码示例
 - C++ wcstombs()用法及代码示例
 - C++ unordered_map end( )用法及代码示例
 - C++ strrchr()用法及代码示例
 - C++ iswalnum()用法及代码示例
 - C++ wcstoll()用法及代码示例
 
注:本文由纯净天空筛选整理自bansal_rtk_大神的英文原创作品 asctime() function in C++。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
