首页 > 编程语言 >学习:python 内置模块 time

学习:python 内置模块 time

时间:2022-08-17 19:56:43浏览次数:57  
标签:-% 内置 秒数 python s2 time print strftime

import time
s1=time.time()#获取一个时间戳:当前时间距离1979年元旦0时的秒数,用户计算程序执行秒数 开始前记录一次 结束后记录一次 相减 
for x in range(1,10001):
    print(x)
s2= time.time()
print(s)
print(s2-s1)

t= time.localtime() #获取当前本地的日期和时间
print(t)

time.strftime("格式",变量名)
time.strftime("%Y-%m-%d---%H:%M:%s",t)
strtime = time.strftime("%Y年-%m月-%d日---%H:%M:%s",t)#将日期和时间转换成指定格式的字符串

time.sleep()#程序休眠,括号内写上休眠的秒数,定时程序使用

#倒计时的小工具
i =10
while i>=0:
    print("倒计时",i)
    time.sleep(1)
    i-=1

 

标签:-%,内置,秒数,python,s2,time,print,strftime
From: https://www.cnblogs.com/datizi/p/16596547.html

相关文章

  • 学习:python 内置模块random
    importrandom#引入模块#创建的文件名项目的名字不要与引入的模块名重复r1=random.randint(1,6)#生成范围随机数r2=random.uniform(1,6)#生成指定范围随机浮点数r3=......
  • 学习:python 模块
    模块是python最高级别的组织单元将程序代码和数据封装起来以便重复使用模块中包含了实现某一类业务的多个函数和属性说的通俗点模块就是一个实现某种业务的工具包,每一......
  • python 日志写入文件
    importloggingfmt="%(asctime)s%(filename)s[line:%(lineno)d]%(levelname)s:%(message)s"logging.basicConfig(level=logging.DEBUG,format=fmt,......
  • 【python error】FutureWarning: The error_bad_lines argument has been deprecated
    前言博主运行python代码的时候出现了warning,主要是模块版本引起的。drawlog.py  warningdrawlog.py:76:FutureWarning:Theerror_bad_linesargumenthasbeend......
  • 【python基础】super的理解
    super() 函数是用于调用父类(超类)的一个方法。super() 是用来解决多重继承问题的,直接用类名调用父类方法在使用单继承的时候没问题,但是如果使用多继承,会涉及到查找顺序......
  • 【python基础】os.listdir乱序问题
    前言想要获取之前某个目录的有序文件,除了文件名称,其他的比如文件内容、创建时间等都发生了改变,不清楚使用os.listdir是否会改变前后的文件排序。可以使用帮助文档查看os.......
  • Python 字符串插值 All In One
    Python字符串插值AllInOne#!/usr/bin/envpython3#coding=utf-8__author__='xgqfrms'__editor__='vscode'__version__='1.0.1'__copyright__="""Co......
  • 【InventWithPython 第一部分】校对活动正式启动
    仓库:https://github.com/apachecn/invent-with-python-zh整体进度:https://github.com/apachecn/invent-with-python-zh/issues/1贡献指南:https://github.com/apachecn/in......
  • python 中的re 常用命令
    importrephoneNumRegex=re.compile(r'zhang(wei|yang|hao)')mo=phoneNumRegex.search('mynumberzhangwei,zhangyang')print(mo.groups())#?前面字符是可选......
  • Python快速排序
    defquicksort(array):less=[]greater=[]iflen(array)<=1:returnarraypivot=array.pop()forxinarray:ifx<=p......