Linux C Get system time

Source: Internet
Author: User

#include <time.h>main () {time_t timep;time (&TIMEP);p rintf ("%s", Asctime (Gmtime (&TIMEP)));}
#include <time.h>main () {time_t timep;time (&TIMEP);p rintf ("%s", CTime (&TIMEP));}
#include <sys/time.h> #include <unistd.h>main () {struct Timeval tv;struct timezone tz;gettimeofday (&TV , &tz);p rintf ("TV_SEC; %d\n ", tv,.tv_sec);p rintf (" TV_USEC; %d\n ", tv.tv_usec);p rintf (" tz_minuteswest; %d\n ", tz.tz_minuteswest);p rintf (" Tz_dsttime,%d\n ", tz.tz_dsttime);}
#include <sys/time.h> #include <unistd.h>main () {struct Timeval tv;struct timezone tz;gettimeofday (&TV , &tz);p rintf ("TV_SEC; %d\n ", tv,.tv_sec);p rintf (" TV_USEC; %d\n ", tv.tv_usec);p rintf (" tz_minuteswest; %d\n ", tz.tz_minuteswest);p rintf (" Tz_dsttime,%d\n ", tz.tz_dsttime);}
#include <time.h>main () {char *wday[]={"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};time_t timep;struct TM *p; Time (&TIMEP);p =localtime (&TIMEP); /* Get local time */printf ("%d%d%d", (1900+p->tm_year), (L+p->tm_mon), p->tm_mday);p rintf ("%s%d:%d:%d\n", wday[p- >tm_wday],p->tm_hour, P->tm_min, p->tm_sec);}
#include <time.h>main () {time_t timep;strcut TM *p;time (&TIMEP);p rintf ("Time ():%d \ n", TIMEP);p =localtime ( &TIMEP) TIMEP = Mktime (P);p rintf ("Time ()->localtime ()->mktime ():%d\n", TIMEP);}
#include <time.h>main () {int seconds= time ((time_t*) NULL);p rintf ("%d\n", seconds);}
    • This article is from: Linux Tutorial Network

Linux C Get system time

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.