For hg, I can set formatting with --template key to output only date, like this:

> hg log -l1 --template "{date(date, '%Y-%m-%d %H:%M:%S')}\n"  
2016-10-07 10:22:41

I can use %z control to output timezone offset:

> hg log -l1 --template "{date(date, '%Y-%m-%d %H:%M:%S %z')}\n"
2016-10-07 10:22:41 +0300

Also, in OpenSuse date realization there is %:::z control for more readable format:

> date +'%Y-%m-%d %H:%M:%S %:::z'
2016-10-07 11:03:34 +03

It's not POSIX control, but is there a way to achieve something like this in hg log formatting? Simple way is not working:

> hg log -l1 --template "{date(date, '%Y-%m-%d %H:%M:%S %:::z')}\n"  
2016-10-07 10:22:41 %:::z

From man date:

%:::z numeric time zone with : to necessary precision (e.g., -04, +05:30)


The isodate filter seems like the closest to what you want.

$ hg log -r1 --template 'date: {date|isodate}\n'
date: 2009-05-05 06:55 +0000

isodate: date keyword. Render the date as a text string in ISO 8601 format. Yields a string like “2006-09-04 15:13:13 -0700”.

To condense the timezone doesn't appear to be feasible. It's even mentioned in this SO Q&A titled: Stripping hg date.

Therefore I think you're best option will be to enlist the help using sed or awk to cleanup the output to suit your needs.


| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.