【发布时间】:2018-12-22 08:28:46
【问题描述】:
我有以下程序演示asctime 的使用。
#include <stdio.h>
#include <time.h>
int main(void) {
struct tm broken_down;
broken_down.tm_year = 2000 - 1900;
broken_down.tm_mon = 0;
broken_down.tm_mday = 1;
broken_down.tm_hour = broken_down.tm_min = broken_down.tm_sec = 0;
printf("Current date and time: %s", asctime(&broken_down));
}
此程序在ideone.com 上打印Current date and time: Sun Jan 1 00:00:00 2000,即日期字段是用空格填充的。
当我用 MSVC 编译和运行这个程序时,它会在月份中生成带有前导零的日期字符串:Current date and time: Sun Jan 01 00:00:00 2000。
造成这种差异的原因是什么?哪种格式正确?
【问题讨论】:
标签: c visual-c++ language-lawyer msvcrt time.h