python 输出上个月的月末日期实例

yipeiwu_com6年前Python基础

如下所示:

import dateutil
def before_month_lastday(ti):
  today=dateutil.parser.parse(str(ti))
  first = datetime.date(day=1, month=today.month, year=today.year)
  lastMonth = first - datetime.timedelta(days=1)
  cc=str(lastMonth.year)+str(lastMonth.month)+str(lastMonth.day)
  return int(cc)
print(before_month_lastday(20171011))
2017930

以上这篇python 输出上个月的月末日期实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python添加菜单图文讲解

python添加菜单图文讲解

分享一个基于tkinter的菜单程序添加操作,希望对需要的朋友有帮助。 打开python集成开发环境,使用 from tkinter import Tk from tkinter im...

使用Python的Flask框架表单插件Flask-WTF实现Web登录验证

使用Python的Flask框架表单插件Flask-WTF实现Web登录验证

表单是让用户与我们的网页应用程序交互的基本元素。Flask 本身并不会帮助我们处理表单,但是 Flask-WTF 扩展让我们在我们的 Flask 应用程序中使用流行的 WTForms 包...

Python中特殊函数集锦

Python中特殊函数集锦

以下内容主要针过滤函数filter , 映射和归并函数map/reduce , 装饰器@ 以及 匿名函数lamda,具体内容如下: 1. 过滤函数filte...

Python适配器模式代码实现解析

Python适配器模式,代码,思考等 # -*- coding: utf-8 -*- # author:baoshan class Computer: def __init__(...

Python中使用pypdf2合并、分割、加密pdf文件的代码详解

朋友需要对一个pdf文件进行分割,在网上查了查发现这个pypdf2可以完成这些操作,所以就研究了下这个库,并做一些记录。首先pypdf2是python3版本的,在之前的2版本有一个对应p...