在本文中,我们将讨论localtime()C ++ STL中函数的工作,语法和示例。
localtime()啊localtime()函数是C ++ STL中的内置函数,在<ctime>头文件中定义。localtime()用于将给定时间转换为本地时间。
此函数使用计时器引用的值并填充结构的值,并将其转换为给定的本地时区
localtime(time_t *timer);
该函数接受以下参数-
timer-它是一个指向具有time_t类型值的对象的指针。
该函数返回一个指针,该指针指向存储在本地时区中的时间结构。
#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