GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::localtime(3) C++ Standard Libary std::localtime(3)

std::localtime - std::localtime


Defined in header <ctime>
std::tm* localtime( const std::time_t *time );


Converts given time since epoch as std::time_t value into calendar time, expressed
in local time.


time - pointer to a std::time_t object to convert


pointer to a static internal std::tm object on success, or null pointer otherwise.
The structure may be shared between std::gmtime, std::localtime, and std::ctime, and
may be overwritten on each invocation.


This function may not be thread-safe.


POSIX requires that this function sets errno to EOVERFLOW if it fails because the
argument is too large.


POSIX specifies that the timezone information is determined by this function as if
by calling tzset, which reads the environment variable TZ.

// Run this code


#include <iostream>
#include <sstream>
#include <iomanip>
#include <ctime>


int main()
{
setenv("TZ", "/usr/share/zoneinfo/America/Los_Angeles", 1); // POSIX-specific


std::tm tm{}; // zero initialise
tm.tm_year = 2020-1900; // 2020
tm.tm_mon = 2-1; // February
tm.tm_mday = 15; // 15th
tm.tm_hour = 10;
tm.tm_min = 15;
tm.tm_isdst = 0; // Not daylight saving
std::time_t t = std::mktime(&tm);


std::cout << "UTC: " << std::put_time(std::gmtime(&t), "%c %Z") << '\n';
std::cout << "local: " << std::put_time(std::localtime(&t), "%c %Z") << '\n';
}


UTC: Sat Feb 15 18:15:00 2020 GMT
local: Sat Feb 15 10:15:00 2020 PST


converts time since epoch to calendar time expressed as Universal
gmtime Coordinated Time
(function)
localtime
localtime_r converts time since epoch to calendar time expressed as local time
localtime_s (function)
(C23)
(C11)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.