我是C的新手.当我练习C来隐蔽时间来刺激来回构造tm时.我注意到了一些差异.请告诉我做错了什么.
#include <string.h>
#include <stdio.h>
#include <time.h>
/*
test different format string to strptime
" %A, %b %d, %X %z %Y "
" %A, %b %d, %X %Z %Y "
*/
int main(int argc,char *argv[])
{
char date[] = "6 Mar 2001 12:33:45";
char fmt[80];
struct tm tm;
if (argc==1) return 0;
strcpy(fmt,argv[1]);
memset(&tm, 0, sizeof(struct tm));
if (strptime(date,"%d %b %Y %H:%M:%S",&tm)==NULL) printf("error\n");
char buf[128];
strftime(buf, sizeof(buf), fmt, &tm);
printf("%s\n", buf);
printf("%d\n", tm.tm_isdst);
if (strptime(buf,fmt,&tm)==NULL) printf("error\n");
else {
printf("year: %d; …Run Code Online (Sandbox Code Playgroud)