Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP timestamp to HTML 5 input type=datetime element

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?

like image 436
thatidiotguy Avatar asked Oct 02 '12 17:10

thatidiotguy


2 Answers

HTML5 Input time is something like this : 1985-04-12T23:20:50.52

You can do that in PHP like this :

echo date("Y-m-d\TH:i:s");

Output

2012-10-02T19:12:49

HTML with Timestamp

<input type="datetime"  value="<?php echo date("Y-m-d\TH:i:s",$timestamp); ?>"/>
like image 172
Baba Avatar answered Oct 01 '22 10:10

Baba


The other examples are both the old way to produce a valid timeStamp format for the TIME element -- the new hotness in php:

<time><?php echo date(DATE_W3C); ?></time>

That will generate a format like:

"2013-05-19T06:40:08+00:00"

like image 28
cameron Avatar answered Oct 01 '22 12:10

cameron