cygwin 上的 C 运行时和日期命令

C runtime and date command on cygwin

背景

$ uname -a
CYGWIN_NT-6.1 Owner-PC 1.7.34(0.285/5/3) 2015-02-04 12:14 x86_64 Cygwin

PS: 15 天前刚刚更新了 Cygwin。应该非常接近电流。

$ date --version
date (GNU coreutils) 8.23
Packaged by Cygwin (8.23-4)
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by David MacKenzie.

摘自 cygwin 的手册页:

 %c     locale's date and time (e.g., Thu Mar  3 23:05:25 2005)

C 运行时的输出(dtime 是一小段代码):

$ ./dtime -f "%c"
Tue Feb  5 17:04:45 2030

我觉得不错... 为了避免这样的问题:代码是什么样的:

strcpy(p->fmt, "%c");
.... 
strftime(tmp, 80, p->fmt, localtime(&lt)); 
printf("%s\n", tmp);

我在 C 库中编写的 dtime 和其他时间例程的行为符合标准。没问题。

另一方面,日期命令不正确 AFAICT:

Owner@Owner-PC ~
$ date
Sun, Feb 22, 2015 11:41:44 AM

Owner@Owner-PC ~
$ date +%c
Sun, Feb 22, 2015 11:41:55 AM

我认为第二行输出不符合手册页或标准。

问题: 错误?我还缺少其他东西吗?

编辑:根据建议引用格式字符串。否。仅当格式

中有空格时才需要
Owner@Owner-PC ~
$ date '+%c'
Sun, Feb 22, 2015  3:13:51 PM

这似乎与区域设置有关。您的 C 程序默认使用 C 语言环境,日期将根据环境变量 LANG、LC_TIME 和 LC_ALL 运行。这些变量的值是多少?你能测试一下吗:

LC_ALL="C" date '+%c'