Create a Post Date/Time with Python

I like to create draft posts as kind of markers for things I want to write about in the future. Unfortunately, when I do a hugo new post..., the current date is already put in the front matter for me. That’s really handy if I’m posting right away, but not so much if I have a draft for a really long time.

If you have Python installed on your system, here’s a quick one-liner to print out the current date/time in Hugo’s (really Go’s) format:

python -c "import time; print time.strftime('%Y-%m-%dT%H:%M:%S', time.localtime()) + '%+03i:00' % (-1*(time.altzone / 3600) if time.daylight else (-1*(time.timezone/3600)));"

I have that line wrapped in a batch file that I can run called htime.bat.

It’s quick and easy! It’s slightly easier than just changing it with your text editor.

NOTE: This command only takes into consideration timezones that change on the hour! Sorry India (and more)…

UPDATE 8/10/2015: I just came across the hugo undraft command that does basically the same thing.