在 python odoo 中格式化字符串
Format string in python odoo
如何在 python 中格式化日期?
示例:
dt = datetime.datetime.strptime("3.3.2017", '%d.%m.%Y')
print '{2}-{1}-{0}'.format(dt.day, dt.month, dt.year)
控制台return:2017-3-3
如何获取日期:
2017-3-3 -- > 2017-03-03
2017-3-13 -- > 2017-03-13
2017-10-10 -- > 2017-10-10
所有日期的长度必须为 10 个字符。
试试这个:
dt_test = dt.strftime('%Y-%m-%d')
print(dt_test, type(dt_test))
2017-03-03 <class 'str'>
只需尝试:
dt = datetime.datetime.strptime("3.3.2017", '%d.%m.%Y')
print '{2}-{1:02d}-{0:02d}'.format(dt.day, dt.month, dt.year)
输出:
2017-03-03
如何在 python 中格式化日期?
示例:
dt = datetime.datetime.strptime("3.3.2017", '%d.%m.%Y')
print '{2}-{1}-{0}'.format(dt.day, dt.month, dt.year)
控制台return:2017-3-3
如何获取日期:
2017-3-3 -- > 2017-03-03
2017-3-13 -- > 2017-03-13
2017-10-10 -- > 2017-10-10
所有日期的长度必须为 10 个字符。
试试这个:
dt_test = dt.strftime('%Y-%m-%d')
print(dt_test, type(dt_test))
2017-03-03 <class 'str'>
只需尝试:
dt = datetime.datetime.strptime("3.3.2017", '%d.%m.%Y')
print '{2}-{1:02d}-{0:02d}'.format(dt.day, dt.month, dt.year)
输出:
2017-03-03