tags:

views:

169

answers:

3

example:

$date = 'Wed, 18 Feb 2009 16:03:52 GMT';

//How can I get $date to equal the current time in the same format?

+1  A: 

I'm not sure I completely understand, but if you merely want to convert the string, you can use strtotime().

Jonathan Sampson
+2  A: 

I assume you mean how to get similar format as that? As there is no exact match in the predefined date constants, this would do it:

$date = gmdate('D, j M Y H:i:s e');

That would return the current date and time in the same format as 'Wed, 18 Feb 2009 16:03:52 GMT'.

EDIT

GMT and UTC are (in normal cases) completely interchangeable, and as gmdate always returns an GMT/UTC date, you can just use this:

$date = gmdate('D, j M Y H:i:s').' GMT';

Or, as it turns out, you can replace e with T to get GMT:

$date = gmdate('D, j M Y H:i:s T');
Tatu Ulmanen
Looks good but I'm trying to fill the value of a web header that is very specific about the format. The above function returns something like: Tue, 15 Dec 2009 20:59:04 UTCDo you know why the UTC at the end instead of th GMT and if there is anything I can do to make it GMT instead?
stormist
my version is much shorter ;-)
streetparade
@stormist: Just change the "e" to "T": $date = gmdate('D, j M Y H:i:s T'); "e" is the identifier ("UTC", "America/Chicago") and "T" is the abbreviation ("GMT", "CST").
GZipp
+1  A: 
$date = gmdate(DATE_RFC822);
streetparade
RFC 822 returnf for example: 'Mon, 15 Aug 05 15:52:01 +0000', not *exactly* what the OP wanted.
Tatu Ulmanen
Tatu beat me to it, nice try though I did check it out
stormist