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::gmtime(3) C++ Standard Libary std::gmtime(3)

std::gmtime - std::gmtime


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


Converts given time since epoch as std::time_t value into calendar time, expressed
in Coordinated Universal Time (UTC).


time - pointer to a 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.

// Run this code


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


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


std::tm tm{}; // get_time does not set all fields hence {}
tm.tm_year = 2020-1900; // 2020
tm.tm_mon = 7-1; // July
tm.tm_mday = 15; // 15th
tm.tm_hour = 10;
tm.tm_min = 15;
tm.tm_isdst = 1; // Daylight saving in London
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: Wed Jul 15 09:15:00 2020 GMT
local: Wed Jul 15 10:15:00 2020 BST


localtime converts time since epoch to calendar time expressed as local time
(function)

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.