首页 > 编程语言 >python时间相关

python时间相关

时间:2023-05-08 16:22:05浏览次数:39  
标签:-% python 博客 datetime 时间 time print 相关

目录

time

time — Time access and conversions — Python 3.10.0 documentation

import time

# 1970-01-01 00:00:00 到现在经过了多少秒
print(time.time())

# 返回一个时间元组
print(time.localtime())

# 时间转字符串
print(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime()))

# 字符串转时间
print(time.strptime('2021-10-15 15:25:04','%Y-%m-%d %H:%M:%S'))

datetime

datetime — Basic date and time types — Python 3.10.0 documentation

from datetime import datetime

# 当前时间
print(datetime.now())

# 时间转字符串
print(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))

# 字符串转时间
print(datetime.strptime('2017-3-22 15:25:01','%Y-%m-%d %H:%M:%S'))

参考博客

python与时间相关的库_szuhuanggang的博客-CSDN博客

python——time库整理(基础知识+实例) - 知乎 (zhihu.com)

Python datetime模块详解、示例_Steven的博客-CSDN博客_python中的datetime

Python中time模块详解_You_are_my_dream的博客-CSDN博客

python datetime与timestamp_dudu3332的博客-CSDN博客

标签:-%,python,博客,datetime,时间,time,print,相关
From: https://www.cnblogs.com/zhanghad/p/17382188.html

相关文章

  • python Django校验表单登录案例
    定义一个视图函数,用于处理登录表单的提交动作。在该视图函数中,使用request.POST.get()方法获取POST请求中提交的用户名和密码数据,具体代码如下:fromdjango.shortcutsimportrender,redirectfromdjango.contrib.authimportauthenticate,logindeflogin_view(requ......
  • python 自动化测试案例
    使用Selenium与unittest框架的自动化测试案例,可以用来模拟浏览器自动打开网站并提交表单:在下述代码中,我们定义了一个继承自unittest.TestCase的测试类TestLoginForm,其中setUp()方法在每个测试方法执行前会调用,用来启动浏览器并打开测试用网站。tearDown()方法在每个测......
  • 电力电子相关仿真,并网逆变器仿真有模块版本,和c语言版本,方便移植。
    电力电子相关仿真,并网逆变器仿真有模块版本,和c语言版本,方便移植。并网逆变器模型预测电流控制仿真,有单矢量,双矢量三矢量等多种。ID:6699672831165332......
  • 微信小程序实现类似elementUI的Timeline时间线效果,自适应页面与文本
    <viewclass="box"><viewwx:for="{{list}}"wx:key="index"class="one"><viewclass="onedot"></view><viewwx:if="{{index!=list.length-1}}"class="oneline......
  • python selenium 谷歌浏览器指定下载位置
    pythonselenium谷歌浏览器指定下载位置功能pythonselenium点击浏览器的下载按钮,然后下载到指定的目录,而非下载到默认位置代码importos.pathfromtimeimportsleepfromseleniumimportwebdriverfromselenium.webdriver.common.byimportBy"""指定默认下载路径,......
  • Python处理文档中的文本
    提取所有Word文档中的指定部分内容,并合并到一个txt文件中:importglobimportdocxdefget_text_between_headings(doc,heading1,heading2):start=-1end=-1foriinrange(len(doc.paragraphs)):ifdoc.paragraphs[i].text==heading1:......
  • C++和Python && 和||运算符之不同点
    ......
  • How to use Linux command or Python code get Raspberry PI's Temperature All In On
    HowtouseLinuxcommandorPythoncodegetRaspberryPI'sTemperatureAllInOne如何使用Linux命令或Python代码获取RaspberryPI的温度raspberrypicheckthetemperatureimportgpiozeroasgz#readthetemperatureintoavariable:cpu_temp=gz.CPUTe......
  • Android Studio相关问题
    下载去官网下载即可,最新版如果运行不了,可选择安装其他版本,我安装的就是4.0版本建立项目一般就是建立一个空项目如果使用过idea,那么建立项目就很简单。因为Android Studio和idea 界面都差不多,功能也类似步骤:File——New——New Project 会出现以下画面:然后选择Empty......
  • python 下载并显示图片
    fromPILimportImage,ImageTkimportrequestsimporttkinter#导入Tkinter模块#importtkpaa='aaa.gif'url='http://www.baidu.com/img/baidu_jgylogo3.gif'defdownLoadImage(name,url):r=requests.get(url)#printr.c......