C++ 中的 localtime() 函数
在本文中,我们将会讨论 C++ STL 中 localtime() 函数的工作原理、语法和示例。
什么是 localtime()?
localtime() 函数是 C++ STL 中的一个内置函数,定义在 <ctime> 头文件中。localtime() 用于将给定的时间转换为本地时间。
此函数使用 timer 引用值并填入结构值,然后将其转换为给定的本地时区
语法
localtime(time_t *timer);
参数
该函数接受以下参数:−
- timer − 指向具有 time_t 类型值的对象的指针。
返回值
此函数返回一个指向 time 结构的指针,该 time 结构存储在本地时区中。
示例
#include <bits/stdc++.h>
using namespace std;
int main(){
time_t hold;
hold = time(NULL);
tm* hold_local = localtime(&hold);
cout<<"Current local time of system is: "<< hold_local->tm_hour << ":"<<hold_local->tm_min << ":"<<hold_local->tm_sec;
return 0;
}输出
Current local time of system is: 8:28:57
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP