C language Time () function: Gets the current times (in seconds)
header file:
To define a function:
Function Description: This function returns the number of seconds elapsed from 0:0 UTC, January 1, 1970, from 0 seconds to the current time. If T is not a null pointer, this function also saves the return value to the memory referred to by the T pointer.
Return value: Success returns the number of seconds, Failure returns ((time_t)-1) value, the reason for the error is in errno.
Example
#include <time.h>
Main () {
int seconds = time ((time_t*) NULL);
printf ("%d\n", seconds);
}
Execution results:
C language Gmtime () function: Get current time and date
header file:
To define a function:
struct TM *gmtime (const time_t *TIMEP);
Function Description: gmtime () Converts the information in the time_t structure of the parameter TIMEP to the time-date representation used in the real world, and then returns the result from the structure TM.
The structure TM is defined as
struct tm{
int tm_sec//representing the current number of seconds, normal range is 0-59, but allowed to 61 sec
int tm_min;//represents current score, range 0-59
int tm_hour;//number of hours from midnight, range is 0-23
int Tm_mday///Current month, range 01-31
int tm_mon;//representing the current month, from January onwards, range from 0-11
int tm_year;//number
of years since 1900 int tm_wday; The number of days in a week, starting from Monday, the range is 0-6
int tm_yday//The number of days since January 1 of this year, the range is 0-365
int tm_isdst;//Daylight saving time flag
};
The date returned by this function is not time zone conversion, but UTC time.
Return value: Returns the structure TM representing the current UTC time.
Example
#include <time.h>
Main () {
char *wday[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
time_t TIMEP;
struct TM *p;
Time (&TIMEP);
p = gmtime (&TIMEP);
printf ("%d%d%d", (1900+p->tm_year), (1+p->tm_mon), p->tm_mday);
printf ("%s%d;%d;%d\n", Wday[p->tm_wday], P->tm_hour, P->tm_min, p->tm_sec);
Execution results: