time模块&datetime模块
import time
a=time.localtime(time.time())
#将时间戳转换为当前时区的元组
print(a) c=time.gmtime(time.time())
#把时间戳转换成0时区的元组默认当前时间
print(c) b=time.time()
#获取一个当前时间的时间戳默认当前时间
print(b) d=time.mktime(a)
#将一个时间元组转换为时间戳
print(d) e=time.sleep(1)
#延时执行后面的语句,单位秒
print(e) f=time.asctime(a)
#将一个时间元组转换成Sun Mar 10 12:22:332019这种形式,默认值time.localtime()
print(f) j=time.ctime()
#将时间戳转换为time.asctime()的形式默认为time.time()
print(j) k=time.strftime("%Y-%m-%d %X",time.localtime(1552192726.5277603))
#拿到一个格式和一个时间元组转换为格式化时间字符串
print(k) g=time.strptime(k,"%Y-%m-%d %X")
#获取一个格式化时间字符串,获取一个格式,转换为时间元组,视为strftime()的反操作
print(g)
import datetime a=datetime.datetime.now()
#返回当前时间日期对象
print(a) #打印当前时间
print(a.timestamp())
#打印当前时间戳 print(a.year)
#打印当前年份 print(a.timetuple())
#获取当前时间元组 b=datetime.date.fromtimestamp(a.timestamp())
#将一个时间戳转换为一个日期
print(b) c=datetime.timedelta(4,hours=3)
#获取一个参数转换为对应时间
#默认接受天数,hours为小时
#用于与datetime.datetime.now()运算
print(c)
#例如:
c=a+c
#时间运算
print(a)
print(c) d=datetime.date(2017,1,30)
#获取年月日生成一个日期
print(d)
d=d.replace(2017,2,28)
#更改日期数据
print(d)
time模块&datetime模块的更多相关文章
- Python模块01/自定义模块/time模块/datetime模块/random模块
Python模块01/自定义模块/time模块/datetime模块/random模块 内容大纲 1.自定义模块 2.time模块 3.datetime模块 4.random模块 1.自定义模块 1. ...
- Python全栈之路----常用模块----datetime模块详解
相比于time模块,datetime模块的接口则更直观,更容易调用. datetime模块定义了下面这几个类: datetime.date:表示日期的类,常用的属性有year,month,day: d ...
- python模块-datetime模块
上面一篇已经讲了time模块,再来学习datetime模块. datetime主要有datetime.timedelta.time.date这4个子模块. a.datetime常用的函数(dateti ...
- 常用模块 - datetime模块
一.简介 datetime是Python处理日期和时间的标准库. 1.datetime模块中常用的类: 类名 功能说明 date 日期对象,常用的属性有year, month, day time 时间 ...
- 模块-os.system的两个模块/random模块/datetime模块/写日志
一.获取当前目录的路径 os.path.abspath('.')# 取绝对路径 os.getcwd()# 取当前路径 .代表当前目录 ..上一级目录 ../.. 二.执行操作系统命令1.os.syst ...
- Python3 time模块&datetime模块&random模块
''' time模块 ''' # import time # print(help(time)) # help()提供帮助 # print(time.time()) # 1970年开始到现在的秒数(时 ...
- time模块/datetime模块/calendar模块
time模块时间的表示形式时间戳:以整型或浮点型表示⼀个时间,该时间以秒为单位,这个时间是以1970年1⽉1⽇0时0分0秒开始计算的. 导入time import time 1.返回当前的时间戳 no ...
- time模块 datetime 模块 random 模块 OS 模块 sys 模块 hashlib 模块
time模块 在python中的时间表现形式: 时间戳 (自1970-01-01-00-00 到当前时间,按秒计算,一共过了多少秒 格式化时间 返回的是时间的字符串 格式化时间对象 返回的是一个元组 ...
- python模块 | 时间处理模块—datetime模块
在python中,与时间处理相关的模块有 time,datetime,calendar. 时间的两个概念: UTC(世界协调时): 整个地球分为二十四时区,每个时区都有自己的本地时间.格林威治天文时间 ...
随机推荐
- export html to canvas image
export html to canvas image canvas.toDataURL https://developer.mozilla.org/en-US/docs/Web/API/HTMLCa ...
- Prettier All In One
Prettier All In One .prettierrc.js / .prettierrc / .prettierrc.json module.exports = { singleQuote: ...
- React Hooks: useImperativeHandle All In One
React Hooks: useImperativeHandle All In One useImperativeHandle https://reactjs.org/docs/hooks-refer ...
- React Hooks: useReducer All In One
React Hooks: useReducer All In One useReducer https://reactjs.org/docs/hooks-reference.html#usereduc ...
- js animation & requestAnimationFrame
js animation & requestAnimationFrame https://developer.mozilla.org/en-US/docs/Web/API/window/req ...
- postman 发送数组
原文 users[]:aa users[]:22 object[] // { users: [ { name: ' "ajanuw"', pwd: ' "aaa" ...
- 两百万SPC空投来袭,带动市场热情!
NGK投放项目的时间节点总是以牛市为主,像是上一次的BGV项目投放就在2020年末的数字加密货币牛市,其结果想必各位生态建设者们都已经见到了,在登陆交易所首日便高收于近889美金,创下惊人的近一千七百 ...
- Datahero inc:区块链方案如何在现有食品溯源系统里实现落地?
在食品行业,区块链溯源平台的应用,主要是指围绕"从农田到餐桌"的安全管理理念,综合运用区块链技术.大数据技术和二维码技术等前沿技术,具有产品生产企业管理. 产品生产档案 (农药/防 ...
- JS数字每三位加逗号的最简单方法
<script> function thousands(num){ var str = num.toString(); var reg = str.indexOf("." ...
- 3分钟学会如何上手supervisor看门狗
软硬件环境 centos7.6.1810 64bit cat /etc/redhat-release #查看系统版本 supervisor 3.4.0 python 2.7.5 supervisor简 ...