编程语言
首页 > 编程语言> > python简单封装时间类

python简单封装时间类

作者:互联网

#!/usr/local/python38/bin/python3
#coding=utf-8

import datetime,time

class OperationTime():

    def timestamp_to_strdatetime(self,timestamp):
        timeArray = time.localtime(timestamp)
        otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
        return otherStyleTime

    def date_time_to_timestamp(self,logintime):
        list_data = list(logintime)
        sdata = str(list_data[0])
        d = datetime.datetime.strptime(sdata, "%Y-%m-%d %H:%M:%S")
        t = d.timetuple()
        timeStamp = int(time.mktime(t))
        return timeStamp

标签:-%,封装,sdata,python,timestamp,简单,list,datetime,time
来源: https://blog.csdn.net/hans99812345/article/details/110196293