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++。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
