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设计】。

相关文章

PyTorch中 tensor.detach() 和 tensor.data 的区别详解

PyTorch0.4中,.data 仍保留,但建议使用 .detach(), 区别在于 .data 返回和 x 的相同数据 tensor, 但不会加入到x的计算历史里,且require...

Python异常的检测和处理方法

捕获异常 # 对数字变量使用append操作 a = 123 a.apppend(4) 执行这个程序时,会抛出: AttributeError: 'int' object h...

Python读取sqlite数据库文件的方法分析

本文实例讲述了Python读取sqlite数据库文件的方法。分享给大家供大家参考,具体如下: import sqlite3 这是Python内置的,不需要pip install...

python中for循环把字符串或者字典添加到列表的方法

python中for循环把字符串或者字典添加到列表的方法

python中如何for循环把字符串添加到列表? 实例: 1.单个字符串用for循环添加到列表中: # 把L1中的字符串添加到列表alist里面 L1 = 'MJlifeBlog'...

python使用三角迭代计算圆周率PI的方法

本文实例讲述了python使用三角迭代计算圆周率PI的方法。分享给大家供大家参考。具体如下: 方法1: 复制代码 代码如下:# Calculating PI using trigonom...