Python日子方法变换

Python日子方法变换

字符串日子转为datetime典型

Python日子方法变换

import datetime

time = '1994-01-19 00:00:00'

time = datetime.datetime.strptime(time,'%Y-%m-%d %H:%M:%S')

print(time,type(time))

输入截止:

1994-01-19 00:00:00 <class 'datetime.datetime'>

datetime典型转为字符串典型

import datetime

time = datetime.datetime.strftime(datetime.datetime.now(),'%Y-%m-%d %H:%M:%S')

print(time,type(time))

输入截止:

2020-09-17 13:17:57 <class 'str'>

功夫戳转为datetime典型

10位功夫戳time = datetime.datetime.utcfromtimestamp(float(1580818427))13位功夫戳time = datetime.datetime.utcfromtimestamp(float(1580818427123)/1000)

datetime典型转为功夫戳

time_ = datetime.datetime.timestamp(datetime.datetime.now())

字符串典型转为功夫戳

time_ = ‘1994-01-19 00:00:00’time_ = time.strptime(time_,’%Y-%m-%d %H:%M:%S’)time = timestamp = time.mktime(time_)

获得暂时功夫(含日子)

time = datetime.datetime.now()

获得暂时功夫(不含日子)

time = datetime.datetime.time(datetime.datetime.now())

获得近几天的日子

day = datetime.datetime.today() – datetime.timedelta(days=7)for i in range(7):print(day – datetime.timedelta(days=(-i)))

python日子方法化

分享到 :
相关推荐

Leave a Reply

Your email address will not be published. Required fields are marked *