<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 菜鳥(niǎo)自學(xué)ARM:linux下編程獲取系統(tǒng)時(shí)間和設(shè)置時(shí)間

          菜鳥(niǎo)自學(xué)ARM:linux下編程獲取系統(tǒng)時(shí)間和設(shè)置時(shí)間

          作者: 時(shí)間:2016-11-09 來(lái)源:網(wǎng)絡(luò) 收藏
          獲取時(shí)間有幾種編程方法:

          1

          本文引用地址:http://www.ex-cimer.com/article/201611/317846.htm

          #include
          #include
          main(){
          time_t t;
          struct tm *p;
          time(&t);
          p=gmtime(&t);
          printf("Year :%dn",1900+p->tm_year);
          printf("Month :%dn",1+p->tm_mon);
          printf("Day :%dn",p->tm_mday);
          printf("Hour :%dn",p->tm_hour);
          printf("Minute:%dn",p->tm_min);
          printf("Second:%dn",p->tm_sec);
          printf("Weekday:%dn",p->tm_wday);
          printf("Days :%dn",p->tm_yday);
          printf("Isdst :%dn",p->tm_isdst);

          }

          2

          #include
          #include
          #include

          int main()
          {
          time_t p;
          char s[30];
          time(&p);
          strcpy(s,ctime(&p)) ;
          printf("%sn",s);

          }

          3

          #include
          #include
          #include

          int main()
          {
          time_t p;
          char s[30];
          struct gm *q;
          time(&p);
          q=gmtime(&p);
          strcpy(s,asctime(q)) ;
          printf("%sn",s);

          }

          設(shè)置時(shí)間

          #include
          #include
          #include
          #include
          main()
          {
          time_t t;
          struct tm *p;
          int i;
          struct timeval tv;
          struct timezone tz;
          tz.tz_minuteswest=0;
          tz.tz_dsttime=0;
          time(&p);
          p=gmtime(&t);
          printf("Change your time:n");
          printf("Year:n");
          scanf("%d",&i);
          (*p).tm_year=i-1900;
          printf("Month:n");
          scanf("%d",&i);
          (*p).tm_mon=i-1;
          printf("Date:n");
          scanf("%d",&i);
          (*p).tm_mday=i;
          printf("Hour:n");
          scanf("%d",&i);
          (*p).tm_hour=i;
          printf("Minute:n");
          scanf("%d",&i);
          (*p).tm_min=i;
          printf("Second:n");
          scanf("%d",&i);
          (*p).tm_sec=i;
          t=mktime(p);
          tv.tv_sec=t;
          tv.tv_usec=0;
          settimeofday (&tv , &tz);
          printf("Done!n");
          }



          評(píng)論


          技術(shù)專(zhuān)區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();