tags:

views:

47

answers:

3

So I've got this:

date('c')

which formats it like so:

2010-08-17T08:55:14-07:00

but I need a way to not have the colon in the offset, so maybe it would look like this:

2010-08-17T08:55:14-0700

What solution is there for this? I'm hoping for a slightly different format, rather than getting the string and replacing the last colon (using reg-ex or something).

Ideas?

+4  A: 

Build it up from the constituent parts:

date('Y-m-d\TH:i:sO')

See the date documentation for the different format strings.

The one you're interested in is O:

Difference to Greenwich time (GMT) in hours (Example: +0200)

Instead of P:

Difference to Greenwich time (GMT) with colon between hours and minutes (added in PHP 5.1.3) (Example: +02:00)

Dominic Rodger
Grr, beat me to it.
Rocket
+2  A: 

Interestingly, date(DATE_ISO8601) doesn't give you the colon.

but date('c') does, and the manual states (for 'c'):

ISO 8601 date (added in PHP 5)

Tom Haigh
+1  A: 

Have a look at PHP's date function and try to find other options.

date('Y-m-d\TH:i:sO');  //2010-08-17T08:55:14-0700
Rocket