How to format date in PHP without colon in offset?

So, I have this:

date('c')

which formats it like this:

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

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

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

What is the solution for this? I hope for a slightly different format, instead of getting the string and replacing the last colon (using reg-ex or something else).

+3
timezone php
Aug 17 '10 at 16:00
source share
3 answers

Create it from the constituent parts:

 date('Ymd\TH:i:sO') 

See the date documentation for different format strings.

Are you interested in O :

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

Instead of P :

Difference from Greenwich Mean Time (GMT) with a colon between hours and minutes (added in PHP 5.1.3) (Example: +02: 00)

+8
Aug 17 '10 at 16:04
source share

Interestingly, date(DATE_ISO8601) does not give you a colon.

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

Date ISO 8601 (added in PHP 5)

+10
Aug 17 '10 at 16:06
source share

Take a look at the PHP date function and try to find other parameters.

 date('Ymd\TH:i:sO'); //2010-08-17T08:55:14-0700 
+1
Aug 17 '10 at 16:08
source share



All Articles