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
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.
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
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With