- >>> import datetime
- >>> def firstDayOfMonth(dt):
- ... return (dt+datetime.timedelta(days=-dt.day+1)).replace(hour=0,minute=0,second=0,microsecond=0)
- ...
- >>> print firstDayOfMonth( datetime.datetime(2006,05,13) )
- 2006-05-01 00:00:00
- >>>
- #该片段来自于http://www.codesnippet.cn/detail/150120131653.html
来源: http://www.codesnippet.cn/detail/150120131653.html