Skip to content

Instantly share code, notes, and snippets.

@BenjaminVanRyseghem
Created February 21, 2015 00:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BenjaminVanRyseghem/21876407114dd55a1d97 to your computer and use it in GitHub Desktop.
Save BenjaminVanRyseghem/21876407114dd55a1d97 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import parsedatetime
import sys
from time import mktime
from datetime import datetime
AS_DATE_FORMAT = "%d/%m/%y"
string = sys.argv[1]
cal = parsedatetime.Calendar()
(val, code) = cal.parse(string)
# possible values for code
# 1 = date (with current time, as a struct_time)
# 2 = time (with current date, as a struct_time)
# 3 = datetime
dt = datetime.fromtimestamp(mktime(val))
print dt.strftime(AS_DATE_FORMAT)
@BenjaminVanRyseghem
Copy link
Author

pip install parsedatetime may be require before this to work

Note that AS_DATE_FORMAT may vary based on your machine localization.

On my other machine, the correct value was AS_DATE_FORMAT = "%A, %B %d, %Y %I:%M:%S %p"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment