PHP 时间戳转换:获取、转换和格式化
在PHP中,可以使用time()函数获取当前时间的时间戳,也可以使用strtotime()函数将时间字符串转换为时间戳。
例如,将'2021-01-01 00:00:00'转换为时间戳:
$timestamp = strtotime('2021-01-01 00:00:00');
echo $timestamp; // 输出1609459200
可以使用date()函数将时间戳转换为指定格式的时间字符串:
例如,将时间戳1609459200转换为'2021年01月01日'格式的时间字符串:
$time_str = date('Y年m月d日', 1609459200);
echo $time_str; // 输出2021年01月01日
原文地址: https://www.cveoy.top/t/topic/m5LX 著作权归作者所有。请勿转载和采集!