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(世界协调时): 整个地球分为二十四时区,每个时区都有自己的本地时间.格林威治天文时间 ...
随机推荐
- LeetCode 算法面试题汇总
LeetCode 算法面试题汇总 算法面试题 https://leetcode-cn.com/problemset/algorithms/ https://leetcode-cn.com/proble ...
- HTML5 dataset All In One
HTML5 dataset All In One dataset https://developer.mozilla.org/en-US/docs/Web/API/HTMLOrForeignEleme ...
- SwiftUI & Compose View
SwiftUI & Compose View OK // // ContentView.swift // Landmarks // // Created by 夏凌晨 on 2020/10/2 ...
- node os env reader
node os env reader node-os-env-reader.js #!/usr/bin/env node "use strict"; /** * * @author ...
- HTML spaces types: &   &  
HTML spaces types: & & What is the difference between and https://stackoverflow.co ...
- AST & js interpreter
AST & js interpreter 抽象语法树 & Javascript 解析器 https://astexplorer.net/ https://esprima.org/dem ...
- js & while & do while
js & while & do while https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Stat ...
- js 实现简单的parseInt和parseFloat
function myParseInt(str: string): number { let result = NaN; for (let i = 0; i < str.length; i++) ...
- nasm astrcat_s函数 x86
xxx.asm %define p1 ebp+8 %define p2 ebp+12 %define p3 ebp+16 section .text global dllmain export ast ...
- django学习-7.html模板中include标签使用场景
1.前言 假设一个公司A有一个网站B,且网站B有5个不同的页面分别为C1,C2,C3,C4,C5. 那么,我们在打开这5个不同页面后去查看页面的整体内容,会发现每个页面的顶部内容.底部内容都一模一样. ...