我就废话不多说了,大家还是直接看代码吧~
import datetime
# 时间格式 .%f 毫秒
## "%Y-%m-%dT%H:%M:%S.%f"
# 格式 秒
## "%Y-%m-%dT%H:%M:%S"
# 格式 分钟
## "%Y-%m-%dT%H:%M"
# 将 字符串格式的时间,转成时间毫秒格式
update_time = datetime.datetime.strptime(i["UpdatedAt"][:26], "%Y-%m-%dT%H:%M:%S.%f")
# 将时间格式转成 字符串
update_time = update_time.strftime('%Y-%m-%d %H:%M:%S.%f')
补充:Python T-N天 日期缺失问题
我就废话不多说了,大家还是直接看代码吧~
#! /usr/bin/env python
# -*- coding:utf-8 -*-
from datetime import datetime, date, timedelta
m = [('JD','2018-11-08'),('Aussie FS','2018-10-10'),('Braun FS','2018-11-09'),('Global FS','2018-11-07')]
t = [('JD','2018-09-10'),('JD','2018-09-11'),('JD','2018-09-12'),
('JD','2018-09-13'),
('JD','2018-09-14'),
('JD','2018-09-15'),
('JD','2018-11-08'),
('Aussie FS','2018-10-02'),
('Aussie FS','2018-10-03'),
('Aussie FS','2018-10-04'),
('Aussie FS','2018-10-05'),
('Aussie FS','2018-10-06'),
('Aussie FS','2018-10-07'),
('Aussie FS','2018-10-08'),
('Braun FS','2018-10-28'),
('Braun FS','2018-11-08'),
('Braun FS','2018-10-30'),
('Braun FS','2018-10-31'),
('Braun FS','2018-11-01'),
('Global FS','2018-09-18'),
('Global FS','2018-09-19'),
('Global FS','2018-09-20'),
('Global FS','2018-11-08'),
('Global FS','2018-09-22'),
('Global FS','2018-09-23')
]
mm = '2018-11-08'
for x in range(0, len(m)):
n = []
n_new = []
i = 0
while i < len(t):
if t[i][0] == m[x][0]:
n.append([t[i][0], t[i][1]])
i += 1
n_new = sorted(list(n))
if n_new[-1][1] != mm:
print '%s最大业务时间为:%s,没有到达T-1:%s'%(n_new[-1][0],n_new[-1][1],mm)
def get_nday_list(n):
before_n_days = []
for i in range(1, n + 1)[::-1]:
before_n_days.append(str(date.today() - timedelta(days=i)))
return before_n_days
a = get_nday_list(10)
b = get_nday_list(30)
ttt = []
for x in range(0, len(m)):
d = []
d_new = []
i = 0
while i < len(t):
if t[i][0] == m[x][0]:
d.append([t[i][0], t[i][1]])
i += 1
d_new = sorted(list(d))
print d_new
ll = []
for xx in range(0,len(d_new)):
ll.append(d_new[xx][1])
kk = 0
while kk<len(a):
if a[kk] not in ll:
ttt.append([m[x][0],a[kk]])
kk +=1
print '业务日期缺失的为:%s'%(ttt)
补充:django drf json格式化日期时间带T的问题 基于python的解决方法
# models.py
update_time = models.DateTimeField(verbose_name=u'更新时间', default=timezone.now)
"gmt_created": "2019-05-19T22:47:46.853262"
# serializers.py
class DeviceSerialiser(ModelSerializer):
# 设置日期格式化格式
update_time = serializers.DateTimeField(format='%Y-%m-%d %H:%M:%S')
class Meta:
model = WaterDevice
fields = ('__all__')
以上为个人经验,希望能给大家一个参考,也希望大家多多支持python博客。如有错误或未考虑完全的地方,望不吝赐教。
标签:django
Powered By python教程网 鲁ICP备18013710号
python博客 - 小白学python最友好的网站!