時間戳與字符串時間轉換

 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."<br/>";
echo strtotime($stringtime)."<br/>";
echo date("Y/m/d G:i:s A",strtotime($stringtime));

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章