git --date 时间显示设置格式命令【汇总参数演示】

git --date  显示与当前时间相关的日期

relative
local
default
iso
rfc
short
raw

  

1. --date=relative 显示相对时间,用户本地时区中的时间戳。

 

提交说明时间设置为,比当前时间早 5个小时的时间:relative:5.hours.ago [注]

git commit -m "Test" --date=format:relative:5.hours.ago

当前时间是 12点,提早5个小时,是07点。

 

时间除了用 .点 分割,还可以用 单引号+空格 方式:

git commit -m "Test" --date=format:relative:'4 hours ago'

注:详细看文末 附录二

 

2. --date=local(or--date=iso)以ISO 8601格式显示时间戳。

 

--date=iso8601(or--date=rfc)以RFC 2822格式显示时间戳,通常在电子邮件中找到。

 

3. --date=rfc2822 只显示日期而不显示时间,格式为--date=shortYYYY-MM-DD以内部原始Git格式显示日期。

 

4. --date=raw 显示原始时区中的时间戳(提交者的或作者的)

 

5.--date=format:%c 以系统区域设置的首选格式显示日期(系统时区设置为上海,所以以中文阅读方式) [注]

 

 

 

附录最新参数:https://www.cnblogs.com/wutou/p/17538409.html

 

 附录一:

也可以自定义格式(需要 git 版本 2.6.0 以上)

如:   --date=format:'%Y-%m-%d %H:%M:%S'  会格式化成:2016-01-13 11:32:13

其他的格式化占位符如下: 

%a:星期的缩写。 Abbreviated weekday name 

%A:星期的全名。 Full weekday name 

%b:月份的缩写。 Abbreviated month name 

%B:月份的全称。 Full month name 

%c:适用于区域设置的日期和时间表示 。Date and time representation appropriate for locale 

%d:月中的天作为十进制数字(01 – 31)。 Day of month as decimal number (01   31) 

%H:24小时制的小时(00 – 23)。   Hour in 24-hour format (00   23) 

%I:12小时格式的小时(01 – 12)。Hour in 12-hour format (01   12) 

%j:一年中的天作为十进制数字(001 – 366)。Day of year as decimal number (001   366) 

%m:以十进制数字表示的月份(01 – 12)。Month as decimal number (01   12) 

%M:分钟以十进制数字表示(00 – 59)。Minute as decimal number (00   59) 

%p:当前语言环境的"上午/下午",12小时制的指示器。Current locale's A.M./P.M. indicator for 12-hour clock 

%S:秒作为十进制数字(00 – 59)。Second as decimal number (00   59) 

%U:一年中的周为十进制数字,周日为一周的第一天(00 – 53)。Week of year as decimal number, with Sunday as first day of week (00   53) 

%w:工作日为十进制数字(0 – 6;星期日为0)。Weekday as decimal number (0  –  6; Sunday is 0) 

%W:一年中的星期作为十进制数字,星期一作为星期的第一天(00 – 53)。Week of year as decimal number, with Monday as first day of week (00   53) 

%x:当前语言环境的日期表示。Date representation for current locale 

%X:当前语言环境的时间表示。 Time representation for current locale

%y:无世纪的年份,为十进制数字(00 – 99),也就是年份没有前两位。

%Y:带世纪的年份,以十进制数表示。

%z%Z:时区名称或时区缩写,取决于注册表设置; 如果时区未知,则没有字符。

%%:表示百分号。

 注:表中汉字翻译 及 %y %Y %z %%  参考: [注]

 

附录二:

还可以用以下的格式:该--date选项(在2009年12月的提交02b47cd中为git1.7.0引入)     [注]

--date=format:relative:'5 seconds ago'
--date=format:relative:'5 minutes ago'
--date=format:relative:'5 hours ago'
--date=format:relative:'5 days ago'
--date=format:relative:'3 weeks ago'
--date=format:relative:'5 months ago'
--date=format:relative:'1 year, 2 months ago'
--date=format:relative:'1 year, 9 months ago'
--date=format:relative:'20 years ago'

--date=format:relative:now

--date=format:relative:'6am yesterday'
--date=format:relative:'6pm yesterday'
--date=format:relative:'3:00'
--date=format:relative:'15:00'
--date=format:relative:'noon today'
--date=format:relative:'noon yesterday'

--date=format:relative:'last tuesday'
--date=format:relative:'July 5th'
--date=format:relative:'06/05/2009'
--date=format:relative:'06.05.2009'

--date=format:relative:'Jun 6, 5AM'
--date=format:relative:'5AM Jun 6'
--date=format:relative:'6AM, June 7, 2009'

 

 

 

 

---

参考:

https://www.lmlphp.com/user/151326/article/item/2790918/

http://www.360doc.com/document/17/0110/17/35790033_621574457.shtml

 

posted @ 2023-06-20 12:42  悟透  阅读(1022)  评论(0编辑  收藏  举报