git --date时间显示设置格式命令

悟透 / 2023-06-20 / 原文

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'

 

还可以用以下的格式:该--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'

 

 

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.lmlphp.com/user/151326/article/item/2790918/