If you try to use:

print format_date(time(), 'custom', 'D F j, Y g:i A T') ."\n";

to output a date like this:

Sun Nov. 8, 2009 9:30 PM PST

You instead get:

Sun Nov. 8, 2009 9:30 PM GMT

In format_date() the formatting for the "T" element is passed to gmdate() when it appears it should instead be date().

CommentFileSizeAuthor
#4 format-date-646932-4.patch948 bytesdstol
#1 date_format_gmt.patch737 bytesjbrauer
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jbrauer’s picture

FileSize
737 bytes

Helps if the file's attached...

David_Rothstein’s picture

Status: Needs review » Needs work

I confirmed this (Drupal 6 only) but the patch doesn't seem to work correctly. It prints "7:40pm EST" for me even though it is 2:40pm EST right now.

Is this even possible to fix in Drupal 6, given the way core's timezone handling is done? I think it might be necessary to use Date module here (for example, http://drupalcontrib.org/api/function/date_format_date/6)....?

chrisdfeld’s picture

I had the same problem with format_date() and the workaround was to use the Date module's date_format_date() (as suggested in #2 above).

Here's the equivalent code for the example above.

print date_format_date(date_make_date(time(), null, DATE_UNIX), 'custom', 'D F j, Y g:i A T');

The resulting output will use the current user's timezone setting or the Drupal timezone setting as a fallback. Set the second parameter to date_make_date() to force a specific timezone.

dstol’s picture

Status: Needs work » Needs review
FileSize
948 bytes

Here's a new patch with support for e and P as well. I couldn't replicate problems described in #2.

adamdicarlo’s picture

Status: Needs review » Needs work

I think this needs more work:

1. Can't add support for 'e' -- see #494434 comment #2.
2. Need to update the function's header comment to document support for 'c' and 'P' -- you can adapt my patch from #494434 or improve its wording.

dstol’s picture