开发者

strtotime to convert both date and time [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the开发者_如何学运维 help center. Closed 10 years ago.

can anyone advise how i would convert a date like "Tuesday, 22 June, 2010 00:00" to a unix timestamp using strtotime()? I need to also store the hours and minutes and it's not clear if is best done using strtotime. Thanks for any help!


Due to the second ,, strtotime() will currently not understand your date/time format (remove it and it will work properly).

If you have a static format for the date, using strptime() or DateTime::createFromFormat() are more reliable, and will allow other non-datetime strings in the date to be present as long as you've defined them.

echo DateTime::createFromFormat("l, j F, Y H:i","Tuesday, 22 June, 2010 00:00")->format("c");


strtotime() does convert both date and time. It converts a string to a Unix timestamp.

What is the unix time stamp?

The unix time stamp is a way to track time as a running total of seconds. This count starts at the Unix Epoch on January 1st, 1970. Therefore, the unix time stamp is merely the number of seconds between a particular date and the Unix Epoch. This is very useful to computer systems for tracking and sorting dated information in dynamic and distributed applications both online and client side.

http://www.unixtimestamp.com

You can convert a unix timestamp back to a string using date


strtotime and date can be used to convert to a UNIX timestamp and extract portions of that timestamp respectively.

The combination should do what you need.


$string = "Tuesday, 22 June, 2010 00:00";
$dateString = substr($string,0,-5);
$timeArray = explode(':',substr($string,-5));
$timeStamp = strtotime($dateString) + 60*$timeArray[0] + $timeArray[1];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜