PHP时间戳到HTML 5输入类型=日期时间元素

2022-01-13 00:00:00 input timestamp php html

我在 PHP 中有一个 unix 时间戳 (int).我想在 HTML5 日期时间输入元素中以一种很好的方式显示这个值.我希望能够让用户以一种漂亮的方式看到这个值,并对其进行编辑.有什么好的方法可以做到这一点,还是我在自欺欺人,我将不得不对大量的字符串操作大惊小怪?

I have a unix timestamp (int) in PHP. I want to display this value in a nice manner in the HTML5 datetime input element. I would like to be able to have users see this value in a nice presentable manner, as well as edit it. Is there any nice way of doing this, or am I fooling myself and I am going to have to fuss around with lots of string manipulation?

推荐答案

HTML5 Input time 是这样的:1985-04-12T23:20:50.52

你可以像这样在 PHP 中做到这一点:

You can do that in PHP like this :

echo date("Y-m-dTH:i:s");

输出

2012-10-02T19:12:49

带有时间戳的 HTML

HTML with Timestamp

<input type="datetime"  value="<?php echo date("Y-m-dTH:i:s",$timestamp); ?>"/>

相关文章