Skip to content

Commit 22952e4

Browse files
committed
新增字符串转对象
1 parent 2cbe5a8 commit 22952e4

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

tools/date.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def interval_time(interval_type='year'):
3535
print (u'%s年工作经验' % diff_years) if int(diff_years) > 0 else u'无工作经验'
3636

3737

38-
def time_prety(delta_s):
38+
def time_pretty(delta_s):
3939
"""
4040
时间友好显示
4141
:param delta_s:
@@ -136,7 +136,12 @@ def test():
136136
print datetime.datetime.now() + datetime.timedelta(days=60)
137137

138138
# 显示友好时间
139-
print time_prety(60 * 60 * 24 * 3 + 60 * 60 * 2 + 60 * 3)
139+
print time_pretty(60 * 60 * 24 * 3 + 60 * 60 * 2 + 60 * 3)
140+
141+
# 字符串转对象
142+
print datetime.datetime.strptime('2016-06-06', "%Y-%m-%d").date(), type(datetime.datetime.strptime('2016-06-06', "%Y-%m-%d").date())
143+
print datetime.datetime.strptime('2016-06-06 12:34:54', "%Y-%m-%d %H:%M:%S")
144+
# print datetime.datetime.strptime('2016-06', "%Y-%m-%d %H:%M:%S") # 异常ValueError
140145

141146

142147
if __name__ == "__main__":

0 commit comments

Comments
 (0)