问题描述
我从插件中收到一个datetime。我把它变成一个变量: $ datetime =20130409163705;
实际上翻译成 yyyymmddHHmmss
我需要将这个显示给用户作为交易时间,但看起来不合适。
我想安排它像 09/04/2013 16:37:05
或 09-apr-2013 16:37:05
。
我要去改变字符串的顺序吗?
至于现在我可以想到的是使用 substr 来分隔日期和时间。我仍然不确定如何添加额外的字符并重新排列日期。
为什么不使用日期()
如下所示,尝试这个 $ t = strtotime('20130409163705');
echo date('d / m / y H:i:s',$ t);
并将输出
09/04/13 16:37:05
I receive a datetime from a plugin. I put it into a variable:
$datetime = "20130409163705";
That actually translates to yyyymmddHHmmss
.
I would need to display this to the user as a transaction time but it doesn't look proper.
I would like to arrange it to be like 09/04/2013 16:37:05
or 09-apr-2013 16:37:05
.
How do I go about and change the orders of the string?
As for now I could think is to use substr to separate the date and time. I'm still not sure on how to add the additional characters and rearrange the date.
why not use date() just like below,try this
$t = strtotime('20130409163705');
echo date('d/m/y H:i:s',$t);
and will be output
09/04/13 16:37:05
这篇关于如何在php中重新格式化datetime字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!