这篇文章给大家介绍python的时间语句有哪些呢 ,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
def getCurrentSec(self):
return time.time()-8*60*60
def getCurrentDate(self):
ISOTIMEFORMAT='%Y-%m-%d'
return time.strftime(ISOTIMEFORMAT, time.localtime(time.time()))
def getCurrentTime(self):
ISOTIMEFORMAT='%X'
return time.strftime(ISOTIMEFORMAT, time.localtime(time.time()))
def getCurrentDateTime(self):
ISOTIMEFORMAT='%Y-%m-%d %X'
#将本地时间转换为世界时
return time.strftime(ISOTIMEFORMAT, time.localtime(time.time()-8*60*60))
def string2Time(self, s):
ISOTIMEFORMAT='%Y-%m-%d %X'
return time.strptime( s, ISOTIMEFORMAT )
def Time2ISOString(self, s):
ISOTIMEFORMAT='%Y-%m-%d %X'
return time.strftime(ISOTIMEFORMAT, time.localtime(float(s)))
===================================================================
def GetSecondByDateTime(self, datetimeStr):
# 由日期时间字符串获取秒数(整数)
ISOTIMEFORMAT='%Y-%m-%d %X'
return time.mktime(time.strptime(datetimeStr, ISOTIMEFORMAT))
def GetSecondByDate(self, dateStr):
# 由日期字符串获取秒数(整数)
ISOTIMEFORMAT='%Y-%m-%d'
return time.mktime(time.strptime(dateStr, ISOTIMEFORMAT))
def GetTupleBySecond(self, second):
# 由秒数(整数或浮点数)获得日期时间的元组,形如(年,月,日,时,分,秒,星期,天数,夏令时标志)
ISOTIMEFORMAT='%Y-%m-%d %X'
return time.localtime(second)
def GetDateTimeBySecond(self, second):
# 由秒数(整数或浮点数)获得日期时间字符串
ISOTIMEFORMAT='%Y-%m-%d %X'
return time.strftime(ISOTIMEFORMAT, time.localtime(second))
def GetDateBySecond(self, second):
# 由秒数(整数或浮点数)获得日期字符串
ISOTIMEFORMAT='%Y-%m-%d'
return time.strftime(ISOTIMEFORMAT, time.localtime(second))
关于python的时间语句有哪些呢 就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。