时间戳与字符串时间转换

 python

import datetime
import time
a = '2020-04-08 15:28:59'
stamp = int(time.time())
print(datetime.datetime.fromtimestamp(stamp))
print(time.strftime("%Y-%m-%d %H:%M", time.localtime(stamp)))
print(time.mktime(time.strptime(a,'%Y-%m-%d %H:%M:%S')))

php

date_default_timezone_set('Asia/Shanghai');
$stringtime = date("Y-m-d H:i:s",time());
echo $stringtime."
"; echo strtotime($stringtime)."
"; echo date("Y/m/d G:i:s A",strtotime($stringtime));

 

你可能感兴趣的:(PHP,Python)