Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

strtotime PHP, display date/time

I have an XML file with a "Time" attribute. I am calling this XML into my PHP and giving it the variable $game_time.

An example value for the attribute is "10:30 PM"...

Since it is coming from XML, it is reading "10:30 PM" as a string.

Now my question, how can I convert this string to an actual timestamp?

I think I need to use strtotime somehow, but can't get the syntax right...

I am wanting this XML time to be converted to a timestamp because I am eventually going to compare this time with the server's time and shoot out a conditional output...

Thanks, John

like image 758
John Stamos Avatar asked Dec 21 '22 09:12

John Stamos


2 Answers

you can use:

date_default_timezone_set('America/Los_Angeles');

$xmldata = '10:30 PM';
echo strtotime($xmldata);
echo date('Y-m-d H:i:s', strtotime($xmldata));

that will output:

1314250200

2011-08-24 22:30:00

If you don't specify a DATE, the current day will be use.

like image 175
Book Of Zeus Avatar answered Dec 24 '22 01:12

Book Of Zeus


you can use strtotime

<?
date_default_timezone_set('UTC');
$time_stamp = strtotime("10:00 AM"); //1314180000
echo date("F j, Y, g:i a", $time_stamp); //August 24, 2011, 10:00 am
?>
like image 41
dvdmn Avatar answered Dec 24 '22 00:12

dvdmn