Sha*_*lva 1 php formatting timestamp
我有来自数组的时间字符串,如果不存在10以下的整数值,我想加上前导零.例如我想要
this "8:10:12" to "08:10:12"
this "13:7:14" to "13:07:14"
this "13:25:6" to "13:25:06"
Run Code Online (Sandbox Code Playgroud)
我可以通过":"拆分一个非常混乱的代码,依此类推,但我想知道是否可以通过一行清理代码完成.如果单线无法做到,请回复.我会做那些凌乱的代码.
提前致谢..!
您可以使用PHP日期函数date与strtotime
$str = "8:10:12";
$new_str = date("H:i:s",strtotime($str));
echo $new_str;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
527 次 |
| 最近记录: |