def paserTime(timestamp):
t = time.time()
f=time.localtime(timestamp/1000)
print (t)
print (int(round(t * 1000)))
nowTime = lambda:timestamp
str=time.strftime('%Y-%m-%d %H:%M:%S',f)
print(str)
return str
def now2():
nowTime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print(nowTime)
def nowTime():
t = time.time()
f = time.localtime(int(t))
str = time.strftime('%Y-%m-%d %H:%M:%S', f)
print(str)
return str
def long2Str(longTime):
f = time.localtime(int(longTime))
str = time.strftime('%Y-%m-%d %H:%M:%S', f)
print(str)
return str
def str2time(str):
date_time = datetime.datetime.strptime(str, '%Y-%m-%d %H:%M:%S')
return date_time
def str2timestamp(str):
timstamp=time.mktime(time.strptime(str, '%Y-%m-%d %H:%M:%S'))
return timstamp
def date2datetime(date_param):
date_str = date_param.strftime('%Y-%m-%d %H:%M:%S')
date_time = datetime.datetime.strptime(date_str, '%Y-%m-%d %H:%M:%S')
return date_time
def month():
first_day=datetime.date.today().replace(day=1).strftime('%Y-%m-%d %H:%M:%S')
print(first_day)
_end_time = last_day_of_month(datetime.date.today()).__str__() + ' ' + '23:59:59'
print(_end_time)
def get_current_week():
monday, sunday = datetime.date.today(), datetime.date.today()
one_day = datetime.timedelta(days=1)
while monday.weekday() != 0:
monday -= one_day
while sunday.weekday() != 6:
sunday += one_day
monday_datetime = date2datetime(monday)
sunday_datetime = date2datetime(sunday)
print(monday_datetime)
return monday_datetime, sunday_datetime
def last_day_of_month(any_day):
"""
获取获得一个月中的最后一天
:param any_day: 任意日期
:return: string
"""
next_month = any_day.replace(day=28) + datetime.timedelta(days=4)
return next_month - datetime.timedelta(days=next_month.day)
def last_month():
this_month_start = datetime.datetime(now.year, now.month, 1)
last_month_end = this_month_start - timedelta(days=1) + datetime.timedelta(
hours=23, minutes=59, seconds=59)
last_month_start = datetime.datetime(last_month_end.year, last_month_end.month, 1)
print('---last_month_start = {} last_month_end = {}'.format(last_month_start,last_month_end))
return last_month_start,last_month_end
def this_month():
this_month_start = datetime.datetime(now.year, now.month, 1)
next_month = now.replace(day=28) + datetime.timedelta(days=4)
this_month_end = next_month - datetime.timedelta(days=next_month.day)+ datetime.timedelta(
hours=23, minutes=59, seconds=59)
print('--- this_month_start = {} this_month_end = {}'.format(this_month_start, this_month_end))
return this_month_start,this_month_end
def last_week():
last_week_start = now - timedelta(days=now.weekday() + 7)
last_week_end = now - timedelta(days=now.weekday() + 1)+ datetime.timedelta(
hours=23, minutes=59, seconds=59)
print('--- last_week_start = {} last_week_end = {}'.format(last_week_start, last_week_end))
return last_week_start,last_week_end
def this_week():
this_week_start = now - timedelta(days=now.weekday())
this_week_end = now + timedelta(days=6 - now.weekday())+ datetime.timedelta(
hours=23, minutes=59, seconds=59)
print('--- this_week_start = {} this_week_end = {}'.format(this_week_start, this_week_end))
return this_week_start, this_week_end
if __name__=='__main__':
str='2017-02-28 03:40:10'
now_time = str2time(str)
now =datetime.datetime(now_time.year, now_time.month, now_time.day)
print(last_day_of_month(now))
last_month()
this_month()
last_week()
this_week()```

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)