import datetime
from datetime import timedelta
def get_day_str():
return datetime.datetime.strftime(datetime.datetime.now(), "%Y-%m-%d")
def local2utc(local_dtm):
# 本地时间转 UTC 时间( -8:00 )
return datetime.datetime.utcfromtimestamp(local_dtm.timestamp())
def get_week_start():
"""获取本周的开始时间"""
now = datetime.datetime.now()
now = datetime.datetime.combine(now, datetime.datetime.min.time())
this_week_start = now - timedelta(days=now.weekday())
return this_week_start
def get_today():
"""获取今天的时间"""
now = datetime.date.today()
dt = datetime.datetime.combine(now, datetime.datetime.min.time())
return dt
def get_month_start():
"""获取这个月的开始时间"""
now = datetime.datetime.now()
this_month_start = datetime.datetime(now.year, now.month, 1)
return this_month_start
def get_year_start():
now = datetime.datetime.now()
now = datetime.datetime(year=now.year, month=1, day=1)
return now
网友评论