
![]()
Very Handy Function
PHP's strtotime() function is something that if you know how to use, will prove to be one of the most handiest functions ever when working with timestamps and stuff like that. strtotime -- Parse about any English textual datetime description into a Unix timestamp Don't you like that? PHP gave developers the option to type the time out, and it will provide them with a unix timestamp. Now isn't that living large? So lets say you are working with RSS Feeds, their time formats are really wacked up, and you usually have to use some very complex date() function in order to make them. But the thing is, you don't usually have a way to convert it back to a unix timestamp for maximum portability. <pubDate>Sat, 06 Jan 2007 08:00 EST</pubDate> Thats generally how a feed timestamp looks. Making a PHP function to do all that work for you, and to convert it to a unix timestamp would be a pain. So just use this. echo strtotime ( 'Sat, 06 Jan 2007 08:00 EST' ); What will you get? But a nice unix timestamp output. Pretty slick huh? Let me show you how else you can use it. Other Examples echo strtotime("now"); Yeah, now that is PHP at its best. Not only can you use strtotime to go in the future, but in the past as well. It will automatically calculate that time specified according to the servers time and give you the timestamp relative to that date. Now that comes in handy for anything really, you name it. PHP can do it. ![]() |