linux bash 年的周数 iso-8601

问题描述 投票:0回答:1

如何使用 php 中的 linux date 命令在 linux bash 中打印相等:

php -r '回显日期(“o.W”);'

我在 linux bash 的 %V 中找到了,但是,

我的第一个问题是:

%V 一年中的周数,以星期一为一周的第一天 (01..53) 如果 1 月 1 日所在周有四个或 新的一年中有更多天,则被视为第一周; 否则为上一年第 53 周,下一周 是第 1 周。类似于 ISO 8601(但不是 100% 合规。)

我的第二个问题,我没有在 php 中找到类似的选项,如“o”。

php linux date iso8601
1个回答
0
投票

您可以使用 %G%V 表示 ISO 年和 ISO 周标准,或使用 %Y、%W 表示 %Y、%U 日历周。

检查 linux date 命令的 FORMAT 控制:

 > man date
   ...
   %G     year of ISO week number (see %V); normally useful only with %V
   %V     ISO week number, with Monday as first day of week (01..53)

   %Y     Year YYYY
   %U     week number of year, with Sunday as first day of week (00..53)
   %W     week number of year, with Monday as first day of week (00..53)

 > date --date "01 Jan 2022" "+%G/%V"
 2021/52
© www.soinside.com 2019 - 2024. All rights reserved.