What's the most elegant way to get the end of the day (datetime)?

前端 未结 6 1536
无人及你
无人及你 2021-02-14 10:16

I\'m currently writing some reporting code that allows users to optionally specify a date range. The way it works (simplified), is:

  • A user (optionally) specifies a
6条回答
  •  感情败类
    2021-02-14 11:22

    date = datetime.strftime('')
    
    date.replace(hour=0, minute=0, second=0, microsecond=0)  # now we get begin of the day
    date += timedelta(days=1, microseconds=-1)  # now end of the day
    

提交回复
热议问题