美文网首页
python 获取今天开始时间戳和周开始时间戳

python 获取今天开始时间戳和周开始时间戳

作者: Do_More | 来源:发表于2018-05-23 12:36 被阅读0次
    # 获取今天开始的时间戳
    def get_current_day_begin_timestamp():
        time_string = datetime.fromtimestamp(
            time.time()).strftime('%Y-%m-%d 00:00')
        timestamp = time.mktime(datetime.strptime(
            time_string, "%Y-%m-%d 00:00").timetuple())
        return float(timestamp) - 8 * 60 * 60
    
    # 计算这周开始的时间戳
    def get_current_week_begin_timestamp():
        date1 = datetime.now()
        this_week_start_dt = str(date1-timedelta(days=date1.weekday())).split()[0]
        timestamp = time.mktime(datetime.strptime(this_week_start_dt, "%Y-%m-%d").timetuple())
        return timestamp - 8 * 60 * 60
    

    相关文章

      网友评论

          本文标题:python 获取今天开始时间戳和周开始时间戳

          本文链接:https://www.haomeiwen.com/subject/jrlrjftx.html