python获取当前,昨天,明天时间
import datetime
nowTime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')#现在
pastTimeMinutes = (datetime.datetime.now()+datetime.timedelta(minutes=5)).strftime('%Y-%m-%d %H:%M:%S')#5分钟后
pastTime = (datetime.datetime.now()-datetime.timedelta(hours=1)).strftime('%Y-%m-%d %H:%M:%S')#一小时前
afterTomorrowTime = (datetime.datetime.now()+datetime.timedelta(days=2)).strftime('%Y-%m-%d %H:%M:%S')#后天
yesterday = (datetime.datetime.now()-datetime.timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S')#昨天
tomorrowTime = (datetime.datetime.now()+datetime.timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S')#明天
# print('\n',nowTime,'\n',pastTimeMinutes,'\n',pastTime,'\n',afterTomorrowTime,'\n',tomorrowTime)
print("现在: "+nowTime)
print("5分钟后: "+pastTimeMinutes)
print("一小时前: "+pastTime)
print("后天: "+afterTomorrowTime)
print("昨天: "+yesterday)
print("明天: "+tomorrowTime)
import datetime
nowTime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')#现在
pastTimeMinutes = (datetime.datetime.now()+datetime.timedelta(minutes=5)).strftime('%Y-%m-%d %H:%M:%S')#5分钟后
pastTime = (datetime.datetime.now()-datetime.timedelta(hours=1)).strftime('%Y-%m-%d %H:%M:%S')#一小时前
afterTomorrowTime = (datetime.datetime.now()+datetime.timedelta(days=2)).strftime('%Y-%m-%d %H:%M:%S')#后天
yesterday = (datetime.datetime.now()-datetime.timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S')#昨天
tomorrowTime = (datetime.datetime.now()+datetime.timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S')#明天
# print('\n',nowTime,'\n',pastTimeMinutes,'\n',pastTime,'\n',afterTomorrowTime,'\n',tomorrowTime)
print("现在: "+nowTime)
print("5分钟后: "+pastTimeMinutes)
print("一小时前: "+pastTime)
print("后天: "+afterTomorrowTime)
print("昨天: "+yesterday)
print("明天: "+tomorrowTime)

总结:
+datetime.timedelta(minutes=5) 加5分钟也就是5分钟之后的时间
-datetime.timedelta(days=1) 减1天时间也就是1天前的时间
python获取当前,昨天,明天时间的更多相关文章
- python 获取文件大小,创建时间和访问时间
# -*- coding: UTF8 -*- import timeimport datetime import os 1. '''把时间戳转化为时间: 1479264792 to 2016-11-1 ...
- python 获取文件的修改时间
os.path.getmtime(name) #获取文件的修改时间 os.stat(path).st_mtime#获取文件的修改时间 os.stat(path).st_ctime #获取文件修改时间 ...
- Python获取并输出当前日期时间
取得时间相关的信息的话,要用到python time模块,python time模块里面有很多非常好用的功能,你可以去官方文档了解下,要取的当前时间的话,要取得当前时间的时间戳,时间戳好像是1970年 ...
- python获取指定时间差的时间
在分析数据的时间经常需要截取一定范围时间的数据,比如三天之内,两小时前等等时间要求的数据,因此将该部分经常需要用到的功能模块化,方便以后以后用到的时候复用.在此,也分享给大家. <span st ...
- Python 获取文件的创建时间,修改时间和访问时间
# 用到的知识# os.path.getatime(file) 输出文件访问时间# os.path.getctime(file) 输出文件的创建时间# os.path.getmtime(file) 输 ...
- python 获取前一天凌晨unix时间
# -*- coding:utf-8 -*-import time now_time = int(time.time())day_time = now_time - now_time % 86400 ...
- python获取当前时间、今天零点、235959点、昨天当前时间、明天的当前时间
python获取当前时间.今天零点.23:59:59点.昨天当前时间.明天的当前时间. 关注公众号"轻松学编程"了解更多. 获取当前时间.今天零点 使用timedalte. tim ...
- odoo开发笔记--python获取当天时间
取得时间相关的信息的话,要用到python time模块,python time模块里面有很多非常好用的功能,你可以去官方文档了解下,要取的当前时间的话,要取得当前时间的时间戳,时间戳好像是1970年 ...
- ios 对日期的处理(包括计算昨天时间、明天时间)
NSDate存储的是世界标准时(UTC),输出时需要根据时区转换为本地时间 Dates NSDate类提供了创建date,比较date以及计算两个date之间间隔的功能.Date对象是不可改变的. 如 ...
- python 获取当天和前几天时间数据
python 获取当天和前几天时间数据 import datetime from datetime import datetime, date, timedelta def dayDateRange( ...
随机推荐
- CentOS和Redhat救援模式
当单用户模式无法修复系统时可以使用救援模式 把系统盘插入光驱重启主机 选择救援模式 默认选择 是否设置网络这里选择否 已读写模式挂载 提示系统挂载/mnt/sysimage如果需要恢复运行 chroo ...
- WordPlayer
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...
- 读《Spring源码深度解析》途中问题1
step 1:检查自己的eclipse版本:在help->About Eclipse中查看: step 2:进入 https://github.com/groovy/groovy-eclipse ...
- Maven、SpringBoot框架结构优化
一.创建maven项目,名为test-parent,pom文件如下: ... <artifactId>test-parent</artifactId> <version& ...
- js积累点
window.opener.parent.frames['taskAnswerInfoForm'].location=newUrl;//可以使该frame的页面跳转.不需要再写xxx.location ...
- java8 集合对象间的处理
eg1:List<CarVo> carVoList = carService.getList(carVo); List<String> listVins = carVoList ...
- deepin修改javahome不生效,一直显示openjdk解决
删除/usr/bin/java即可 terwer@terwer-PC:~$ sudo rm /usr/bin/java [sudo] terwer 的密码: terwer@terwer-PC:~$ j ...
- RuntimeError - [Xcodeproj] Unknown object version.解决方法
wjw:layoutInScrollView username$ pod install Analyzing dependencies xcode-select: error: tool 'xcode ...
- display style edit
https://html.spec.whatwg.org/multipage/interaction.html#attr-contenteditable <!doctype html> & ...
- MySQ数据表设计
数据表概念 数据表是数据库中的基本对象元素,以记录(行)和字段(列)组成的二维结构用于存储数据.数据表由表结构和表内容两部分组成,先建立表结构,然后才能输入数据.数据表结构设计主要包括字段名称.字段类 ...