Created
March 16, 2017 14:07
-
-
Save fanhaipeng0403/bb25c775f41c12f2279af90b8260d151 to your computer and use it in GitHub Desktop.
生成当前时间
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import parsedatetime | |
...: from time import mktime | |
...: from datetime import datetime | |
...: | |
...: cal = parsedatetime.Calendar() | |
...: | |
...: | |
...: def parse_human_time(s): | |
...: time_struct, _ = cal.parse(s) | |
...: return datetime.fromtimestamp(mktime(time_struct)) | |
...: | |
In [2]: parse_human_time('d') | |
Out[2]: datetime.datetime(2017, 3, 16, 21, 59, 8) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment