Skip to content

Instantly share code, notes, and snippets.

@amdavidson
Created January 19, 2012 21:15
Show Gist options
  • Save amdavidson/1642652 to your computer and use it in GitHub Desktop.
Save amdavidson/1642652 to your computer and use it in GitHub Desktop.
A quick python script to convert all dates to unix time.
#!/usr/bin/python
import os, sys
import dateutil
import dateutil.parser
import time
import calendar
import fileinput
for line in fileinput.input(inplace=1):
if 'date: ' in line:
old = line.lstrip("date: ").rstrip("\n")
old_mod = old + " PST"
d = dateutil.parser.parse(old_mod, fuzzy=True)
t = time.strptime(d.ctime())
new = time.mktime(t)
line = "date: " + str(new)
print line
else:
print line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment