strptime和strptime函數理解

來源:互聯網
上載者:User

標籤:style   io   資料   for   ar   時間   amp   size   

#include <stdio.h>

       #include <time.h>

 

       int main() {

               struct tm tm;

               char buf[255];

 

               strptime("2001-11-12 18:31:01", "%Y-%m-%d %H:%M:%S", &tm);

               strftime(buf, sizeof(buf), "%d %b %Y %H:%M", &tm);

               puts(buf);

               return 0;

       }

這兩個函數都是時間日期的格式控制函數,在功能上看起來正好相反。

size_t strftime(char *s,size_t maxsize,char *format,const struct tm *timeptr)

作用:strftime將一個tm結構格式化為一個字串

參數:format為輸出資料格式

char *strptime(const char *buf,const char *format,struct tm *timeptr)

作用:strptime則是將一個字串格式化為一個tm結構。

參數:buf為要修改的時間,一般為GPS時間

       Format為資料格式,與buf時間格式必須一致,要不然會有段錯誤

 

%a

星期幾的簡寫形式

%A

星期幾的全稱

%b

月份的簡寫形式

%B

月份的全稱

%c

日期和時間

%d

月份中的日期,0-31

%H

小時,00-23

%I

12進位小時鐘點,01-12

%j

年份中的日期,001-366

%m

年份中的月份,01-12

%M

分,00-59

%p

上午或下午

%S

秒,00-60

%u

星期幾,1-7

%w

星期幾,0-6

%x

當地格式的日期

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.