Strptime and strptime Functions

Source: Internet
Author: User
Tags time and date

# Include <stdio. h>

# Include <time. h>

 

Int main (){

Struct 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;

}

These two functions are the format control functions of the time and date, which seem to be the opposite in terms of functionality.

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

Purpose: strftime format a tm structure as a string

Parameter: format is the output data format.

Char * strptime (const char * Buf, const char * format, struct TM * timeptr)

Purpose: strptime is to format a string into a TM structure.

Parameter: the time when the Buf is to be modified, generally the gps time.

Format is the data format, which must be consistent with the Buf time format. Otherwise, a segment error occurs.

 

%

Day of the week

%

Full name of the day of the week

% B

Abbreviated month format

% B

Full name of month

% C

Date and Time

% D

Date in month, 0-31

% H

Hour, 00-23

% I

Hour in decimal format, 01-12

% J

The date in the year, 001-366

% M

Month in year, 01-12

% M

Minute, 00-59

% P

Morning or afternoon

% S

Seconds, 00-60

% U

Day of the week, 1-7

% W

Day of the week, 0-6

% X

Date in local format

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.