Get Unix timestamp (in seconds) for hg commit
Given a commit with a date Mon Aug 18 21:05:38 2014 +0200
, how can I get the Unix timestamp in seconds?
The following command outputs a number that discards the number (presumably because time zone information has date
been discarded):
$ hg log -l1 --template '{date(date, "%s")}\n'
1408392338
$ date -d@1408392338
Mon Aug 18 22:05:38 CEST 2014
I'm actually looking for the equivalent of a command git
that prints the commit date as a Unix timestamp:
git log -n1 --pretty=%ct
source to share
The requested timestamp was timezone independent, hence UTC time. Since it date(..., "%s")
creates a number relative to the current timezone, we need to query the UTC output by combining the filter localdate
with an environment variable TZ
to set the timezone:
TZ=UTC hg log -l1 --template '{date(date|localdate, "%s")}\n')
source to share
- You can get the changeset date in any format that understand the
-d
date option and use it indate -d -F
- You can use filter keyword
Example
hg log -r tip -T "date: {date}\nhgdate: {date|hgdate}\nISO-date: {date|isodate}\n"
date: 1390885140.0-21600
hgdate: 1390885140 -21600
ISO-date: 2014-01-28 10:59 +0600
I think (too lazy to check) the result of the expression 1390885140-21600
will give you the correct timestamp
source to share