开发者

XML String Converted to Date/Time timestamp

Real quick question:

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 "8:30 PM"...

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

Now my question, how c开发者_StackOverflow中文版an 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...

I hope this makes sense!

Thanks, John


strtotime() should be able to convert something like "8:30 PM" to a Unix timestamp:

$time = strtotime("8:30 PM");

Now $time will contain the timestamp. Note that strtotime will assume the server day/month/year since you didn't specify a date, only a time. If you're comparing only to the server time and not the server date, you can grab the individual components of a timestamp using getdate():

$timeArray = getdate($time);
echo $timeArray['seconds'];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜