-1

Is it possible extract hour value from a date string like below

20151211091805 +0000

expected output-

09:18:05 (this should also be string)

DhruvJoshi
  • 16,585
  • 6
  • 37
  • 57
Elmer
  • 85
  • 9

3 Answers3

1

Try this:

$t = "20151211091805";
echo date('H:i:s',strtotime($t));
Shailesh Katarmal
  • 2,707
  • 1
  • 11
  • 15
0

Use PHP's date function.

echo date("H:i:s", strtotime("20151211091805"));

Another way using DateTime class.

$dateTime = new DateTime("20151211091805");                             
echo $dateTime->format('H:i:s');    
artsylar
  • 2,578
  • 4
  • 33
  • 49
0

Try this..

<?php
 $timestamp = 20151211091805;
 $date = new DateTime("$ts");
 echo date_format($date, 'H:i:s');
?>
Ramesh_Konda
  • 111
  • 3
  • 12