-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
  • 17,041
  • 6
  • 41
  • 60
Elmer
  • 85
  • 9

3 Answers3

1

Try this:

$t = "20151211091805";
echo date('H:i:s',strtotime($t));
Shailesh Katarmal
  • 2,757
  • 1
  • 12
  • 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,648
  • 4
  • 34
  • 51
0

Try this..

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