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

学习:python 内置模块datetime

时间:2022-08-17 20:00:52浏览次数:58  
标签:-% 内置 23 python s2 datetime print d2

import time

import datetime

#获取当前的日期时间
n=datetime.datetime.now()
print(n)
#获取一个指定时间
da=datetime.datetime(2018,2,13,5,23,45)
print(da)
#日期转字符串
s1=d1.strftime("%Y-%m-%d %H%M%S")
print(s1)

#字符串转成日期
s2="2018/02/13 05:23:45"
datetime.datetime.srtptime(s2,"%Y-%m-%d %H:%M:%S")
print(d2,type(d2))

 


 

标签:-%,内置,23,python,s2,datetime,print,d2
From: https://www.cnblogs.com/datizi/p/16596563.html

相关文章

  • 学习:python 内置模块 time
    importtimes1=time.time()#获取一个时间戳:当前时间距离1979年元旦0时的秒数,用户计算程序执行秒数开始前记录一次结束后记录一次相减forxinrange(1,10001):......
  • 学习: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())#?前面字符是可选......