python 时间操作

python

python 的 time 与datetime 模块对时间的操作。

# coding:utf-8

import pandas as pd

import datetime

import time

import numpy as np

start = datetime.datetime.now().strftime('%Y-%m-%d')

end = (datetime.datetime.now()+datetime.timedelta(days=4)).strftime('%Y-%m-%d')

print(start,end)

data = pd.DataFrame(np.random.randint(-10,10,[5,10]),index=pd.date_range(start,end),columns=None)

print(data)

'''

# ******时间撮转时间*********

newDate = time.time()

print(newDate)

time_local = time.localtime(newDate)

print(time_local)

newLocalDate = time.strftime('%Y/%m/%d %H:%M:%S',time_local)

print(newLocalDate)

# *******时间转换时间撮*********

str_df = str(newLocalDate)

print(str_df)

timeArray = time.strptime(str_df,'%Y/%m/%d %H:%M:%S')

print(timeArray)

time_cuo = time.mktime(timeArray)

print(time_cuo)

'''

# datetime库对时间的操作。

date = time.time()

date = datetime.datetime.fromtimestamp(date)

date = date.strftime('%Y-%m-%d %H:%M:%S')

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

date = date.strftime('%Y/%m/%d')

print(date)

以上是 python 时间操作 的全部内容, 来源链接: utcz.com/z/388822.html

回到顶部