struct Tm->time () localtime () gmtime ()

Source: Internet
Author: User
Tags epoch time

struct Tm->time () localtime () gmtime ()

structTM {int tm_sec;/*Represents the current number of seconds, the normal range is 0-59, but allowed to 61 seconds*/int tm_min;/*Represents current score, range 0-59*/int tm_hour;/*Number of hours from midnight, with a range of 0-23*/int tm_mday;/*Number of days in the current month, range 01-31*/int Tm_mon; /* represents the current month, starting from January, ranging from 0-11 */int tm_year; /**/< Span style= "color: #0000ff;" >int Tm_wday; /* The day of the week, from Monday, with a range of 0-6 */int Tm_yday; /* The number of days since January 1 this year, ranging from 0-365 */int tm_isdst; /* Daylight saving Time flag */}; 

Time ()

A function in the C language of a programming language. header file:Time.h function Prototypes:time_t Time (time_t * timer) Features: to get the current system time, the returned result is a time_t type, which is actually a large integer whose value is represented from cut (coordinated Universal time) January 1, 1970 00:0 0:00 (called the epoch Time of the UNIX system) the number of seconds to the current moment. Then call localtime to convert the cut time represented by time_t to local time (we are +8 zones, 8 hours more than cut) and turn into a struct TM type, each data member representing the date and time of the year and seconds. Additional note: The prototype of the time function can also be interpreted as long *tloc, which returns a long integer. Because in time.h this header file, time_t is actually:
/**/#define _TIME_T_DEFINED/* Avoid multiple defines of time_t */#endif  
That's long.
 #include <stdio.h> #include <stddef.h>  #include <time.h>int Main (voidtime_t is a long int type struct TM *tblock;timer = time (NULL); //timer);p rintf ( "local time is:%s\n ",asctime (Tblock)); return 0    
localtime () Features:Converts the number of seconds from 1970-1-1:00 to the current time system to the calendar time. Description:This function obtains the time of the TM struct, which is already in the time zonetranslates to local time. Usage:struct TM *localtime (const time_t *clock); return value: Returns a pointer to the TM structure. The TM struct is a structure defined in time.h for each amount of time (year, month, etc.) that is stored separately.It should be noted that the year plus 1900, the month plus 1.
#include <time.h>#include <stdio.h>int main () {struct tm *t;time_t tt;time (&  TT); T=localtime (&TT);p rintf ("%4d%02d month%02d day%02d:%02d:%02d\n", t->tm_year+1900,t- >tm_mon+1,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec);  0;}              

Gmtime ()

header file:Time.h Prototypes:struct TM *gmtime (long *clock); Features:A function that converts the date and time to Greenwich (GMT) time . Converts the information in the time_t structure referred to by the parameter TIMEP to the time date representation used by the real world, and then returns the result from the Fabric TM. The time date that this function returnsNot a time zone conversion , but UTC time. return value returns the structure TM representing the current UTC time
#include"Stdio.h"#include"Time.h"#include"Stdlib.h"int main (voidarea;tzset (); /* Tzset () */t = time (NULL), area = localtime (&t);p rintf ( "local time is:%s" " GMT is:%s "0       

struct Tm->time () localtime () gmtime ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.