python

import time

str类型的日期转换为时间戳

字符类型的时间

tss1 = '2013-10-10 23:40:00'

转为时间数组

timeArray = time.strptime(tss1, "%Y-%m-%d %H:%M:%S")
print(timeArray)

timeArray可以调用tm_year等

print(timeArray.tm_year)# 2013

转为时间戳

timeStamp = int(time.mktime(timeArray))
print(timeStamp) # 1381419600

时间戳转换为指定格式的日期

timeStamp = 1381419600
otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(timeStamp))
print(otherStyleTime)   # 2013-10-10 23:40:00

php

时间戳转换为指定格式的日期

使用 date(format,timestamp) 函数

date('Y-m-d H:i:s', 具体时间戳)

str类型的日期转换为时间戳

使用 strtotime() 函数

echo strtotime("now");
echo strtotime("+1 day");
echo strtotime("+1 week 2 days 4 hours 2 seconds");
echo strtotime("next Thursday");
echo strtotime("last Monday");
echo strtotime("2017-08-08 23:00:01");
echo strtotime("2009-01-31 +1 month");
×