Datetime 如何在mercurial中获取文件创建/更新时间?

Datetime 如何在mercurial中获取文件创建/更新时间?,datetime,command-line,mercurial,logging,Datetime,Command Line,Mercurial,Logging,我正在写我的博客系统(django),我的博客文件由mercurial进行VCSE 我想在创建/更新文件时获取文件,如何使用命令行或python实现这一点 编辑:这是一个示例: $ SOME_COMMAND xxx.txt 2010-12-13-04:12:12 2010-12-14:04:12:12 xyx.txt 2010-12-13-04:12:12 2010-12-14:04:12:12 xxy.txt 2010-12-13-04:12:12 2010-12-14:04:12:12 yx

我正在写我的博客系统(django),我的博客文件由mercurial进行VCSE

我想在创建/更新文件时获取文件,如何使用命令行或python实现这一点

编辑:这是一个示例:

$ SOME_COMMAND
xxx.txt 2010-12-13-04:12:12 2010-12-14:04:12:12
xyx.txt 2010-12-13-04:12:12 2010-12-14:04:12:12
xxy.txt 2010-12-13-04:12:12 2010-12-14:04:12:12
yxx.txt 2010-12-13-04:12:12 2010-12-14:04:12:12
yyx.txt 2010-12-13-04:12:12 2010-12-14:04:12:12
你可以使用hg日志

temp $ mkdir test
temp $ cd test
test $ hg init .
test $ cp ../a.py .
test $ hg add a.py 
test $ mate a.py 
test $ hg commit -m "added file"
test $ hg commit a.py -m "changed file"
test $ hg log
1[tip]   9c2bcca8ff10   2010-10-27 20:04 -0700   aranjan
  changed file

0   d4f0137215c2   2010-10-27 20:04 -0700   aranjan
  added file

test $ hg log a.py 
1[tip]   9c2bcca8ff10   2010-10-27 20:04 -0700   aranjan
  changed file

0   d4f0137215c2   2010-10-27 20:04 -0700   aranjan
  added file
~/.hgrc、.hg/hgrc


要获取文件的最新修改时间,请执行以下操作:

hg log --template '{date}' -l 1 path/to/file
要获得创建时间,请执行以下操作:

hg log --template '{date}' -r 0:tip -l 1 README
示例输出:

$ hg log --template '{date}' -r 0:tip -l 1 README
1115154970.028800

$ hg log --template '{date}' -l 1 README
1255462070.025200
这些日期值是unix epoc秒,后跟一个点和一个时区偏移量。您可以使用
hg-help-templates
中描述的各种过滤器对它们进行格式化,如下所示:

$ hg log --template '{date|rfc822date}' -l 1 README
Tue, 13 Oct 2009 12:27:50 -0700

我得到的印象是,他是以编程的方式追求这个值的,所以在没有模板的情况下使用日志将意味着必须首先对其进行grep/解析,然后对其进行最后的解析。
hg log --template '{date}' -r 0:tip -l 1 README
$ hg log --template '{date}' -r 0:tip -l 1 README
1115154970.028800

$ hg log --template '{date}' -l 1 README
1255462070.025200
$ hg log --template '{date|rfc822date}' -l 1 README
Tue, 13 Oct 2009 12:27:50 -0700