命令日期执行

命令日期执行

我正在尝试执行此命令date +'%-4.4h %2.1d %H:%M'但输出不正确:

%-4.4h %2.1d 12:50  

我认为我的 ubuntu 终端或代码有问题。有什么建议吗? ps:初学者

答案1

据我所知,%-4.4h%2.1d不是 GNUdate命令的有效格式说明符 - 特别是精度修饰符没有意义且不受支持。可接受的修饰符为:

   After any flags comes an optional field width, as a decimal  number;  then  an  optional
   modifier,  which is either E to use the locale's alternate representations if available,
   or O to use the locale's alternate numeric symbols if available.

(此处的“十进制”仅指数字 0-9)。

完整月份名称和月份日期的格式说明符分别为%B和(对于缩写月份名称,%d可以使用小写%b或 ,例如)。例如:%hSepSeptember

$ date +'%B %d %H:%M'
May 12 07:46

$ date +'%B %d %H:%M' -d 'today + 4 months'
September 12 07:48

$ date +'%b %d %H:%M' -d 'today + 4 months'
Sep 12 07:50

请注意,字段宽度说明符是最低限度宽度,例如

$ date +'%4B %4d %H:%M'
 May 0012 08:04

填充May到 4 个字符,但是

$ date +'%4B %4d %H:%M' -d 'today + 4 months'
September 0012 08:03

不会截断SeptemberSept

man date参阅完整的说明符列表%

相关内容