Python 日期处理
#!/bin/python
#coding=utf-8from datetime import datetime
from datetime import timedelta###################格式化输出 Begin######################
#date>>string
now = datetime.now()
print now.strftime('%Y-%m-%d %H:%M:%S')#string>>date
str_date='2013-11-02 16:26:23'
d=datetime.strptime(str_date,'%Y-%m-%d %H:%M:%S')
print d
###################格式化输出 End############################################日期比较 start#######################
#计算两个日期相差多少天
d1 = datetime.strptime('2013-11-02 16:26:23','%Y-%m-%d %H:%M:%S')
d2 = datetime.strptime('2013-10-02 16:26:23','%Y-%m-%d %H:%M:%S')
diff = d1-d2
print diff.days#计算N天/N周/N秒后的日期
now = datetime.now()
aDate = timedelta(days=5)#负数表示之前
n_days = now +aDate
print n_days.strftime('%Y-%m-%d %H:%M:%S')
delta1 = timedelta(seconds = 600)
delta2 = timedelta(weeks = 3)
print delta1+now
print delta2+now
####################日期比较 start#######################
转载于:https://www.cnblogs.com/devtao/p/3404424.html
Python 日期处理相关推荐
- Python日期字符串到日期对象
本文翻译自:Python date string to date object How do I convert a string to a date object in python? 如何在pyt ...
- 【转载】Python日期时间模块datetime详解与Python 日期时间的比较,计算实例代码
本文转载自脚本之家,源网址为:https://www.jb51.net/article/147429.htm 一.Python中日期时间模块datetime介绍 (一).datetime模块中包含如下 ...
- Python 日期和时间戳的转换
Python 日期和时间戳的转换 1. Python中处理时间的模块 Python中处理时间的模块有time.datetime和calendar. 在Python中表示时间的方式: 时间戳:10位整数 ...
- netflix linux_Netflix如何处理故障转移,Anaconda,Linux命令行技巧,Python日期时间库,GDPR,微服务等
netflix linux 上周,Amjith Ramanujam的页面浏览量超过12,000, 关于Netflix如何在7分钟内完成故障转移的文章是我们失控的热门. 您是否有关于您的组织如何确保最大 ...
- [转载] python日期时间使用详解和定时器使用讲解
参考链接: Python日期时间 python中一个关于日期时间非常重要的模块是datetime模块,使用前先将它导入到项目中,import datetime. 获取当前时间 now=datetime ...
- python日期_Python日期
python日期 Python date class is part of datetime module. Python日期类是datetime模块的一部分. Python日期 (Python da ...
- python 日期格式打印_Python打印格式
python 日期格式打印 In this lesson, we will study about various ways for Python print format, through whic ...
- python日期时间_Python日期时间
python日期时间 Python日期时间 (Python datetime) In this post, we will study about how to use the python date ...
- python 日期API
Python 日期函数 1. 日期输出格式化 datetime => string import datetime now = datetime.datetime.now() now.strft ...
- python 日期时间处理_如何使用Python处理日期和时间
python 日期时间处理 当试图使事情与datetime模块一起工作时,大多数Python用户在我们诉诸猜测直到错误消失之前都面临着一个问题. datetime是似乎易于使用的API之一,但要求开发 ...
最新文章
- 【Groovy】集合遍历 ( 操作符重载 | 集合中的 “ << “ 操作符重载 | 使用集合中的 “ << “ 操作符添加一个元素 | 使用集合中的 “ << “ 操作符添加一个集合 )
- 【Spring MVC 之应用篇】3_SpringMVC常见注解
- iOS 登录功能的实现
- Linux设置路由器ip租约时间,入坑Linux-day15(使用DHCP动态管理主机地址)
- 类中定义自身类的对象
- 书评 – 程序员经典读物(1)
- Oracle 一些常用函数
- Intel CPU 曝两个新漏洞影响所有处理器,设备可遭接管(含视频)
- android内核中Kconfig及如何加自己的驱动
- 线程池创建线程数量讨论
- php投票小程序源码,微信小程序:投票小程序源码
- 微云html网页,微云收藏在哪里_以及腾讯微云收藏网页版怎么用? - 软件教程 - 格子啦...
- uniapp省市区三级联动
- 谁才是商超的救世主?
- CodeWars刷题练习
- Mac 乐固加固 报错/Applications/legutools.app/Contents/PlugIns/JRE/Contents/Home/jre/bin/zipalign: error=
- 新技术预研Android
- Python爬虫实例,一小时上手爬取淘宝评论(附代码)!
- C# WinForm 文件夹选择控件 folderBrowserDialog 的应用实例
- ITSM常见问题之:自动指派工单给对应的技术员的三种简单方法
热门文章
- 录入设备(3)——51单片机原理图及PCB设计
- 解决部署jeesite项目报错 com.thinkgem.jeesite.modules.sys.listener.WebContextListener
- Spring学习笔记——@Configuration和@Bean注解
- cuckoo沙箱配置部署流程
- login 登陆界面
- 做了个面试题:使用TDD思想,用vue3集成自己手写的event bus。
- 解决TortoiseSVN或者TortoiseGit拉取的文件夹不能完整显示绿色打钩、黄色、红色感叹号、蓝色加号等小图标的问题
- matlab版吴恩达机器学习第五章笔记
- OpenCppCoverage 引起测试程序Crash问题
- JVM读书笔记之GC算法