p7-9.c

来自「SUN Solaris8平台下进程间通信」· C语言 代码 · 共 25 行

C
25
字号
#include <time.h>#include <stdio.h>int main(void){    struct tm *tm_ptr,timestruct;    time_t the_time;    char buf[256];    char *result;    (void)time(&the_time);    tm_ptr = localtime(&the_time);    strftime(buf, 256, "%A %d %B, %I:%S %p",tm_ptr);    printf("strftime gives: %s\n",buf);    strcpy(buf,"Mon 1 February 1999 17:53 will do fine");    printf("calling strptime with: %s\n", buf);    tm_ptr = &timestruct;    result = strptime(buf, "%a %d %b %Y %R",tm_ptr);    printf("strptime parsed up to: %s\n",result);    printf("strptime gives:\n");        printf("    date: %02d/%02d/%02d\n",               tm_ptr->tm_year,tm_ptr->tm_mon+1,tm_ptr->tm_mday);        printf("    time: %02d:%02d\n",        tm_ptr->tm_hour,tm_ptr->tm_min);    exit(0);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?