在PHP中,可以使用date()
函數(shù)和strtotime()
函數(shù)來實(shí)現(xiàn)自定義的時(shí)間戳格式轉(zhuǎn)換。
1. 使用date()
函數(shù):
$timestamp = time(); // 獲取當(dāng)前時(shí)間戳
$formatted_date = date("Y-m-d H:i:s", $timestamp); // 轉(zhuǎn)換為 "2023-09-25 14:30:00" 格式
echo $formatted_date;
2. 使用strtotime()
函數(shù):
$timestamp = time(); // 獲取當(dāng)前時(shí)間戳
$formatted_date = date("Y-m-d H:i:s", strtotime(date("Y-m-d H:i:s", $timestamp))); // 轉(zhuǎn)換為 "2023-09-25 14:30:00" 格式
echo $formatted_date;
這兩種方法都可以實(shí)現(xiàn)自定義的時(shí)間戳格式轉(zhuǎn)換。