Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
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().
Comment | File | Size | Author |
---|---|---|---|
#4 | format-date-646932-4.patch | 948 bytes | dstol |
#1 | date_format_gmt.patch | 737 bytes | jbrauer |
Comments
Comment #1
jbrauer CreditAttribution: jbrauer commentedHelps if the file's attached...
Comment #2
David_Rothstein CreditAttribution: David_Rothstein commentedI 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)....?
Comment #3
chrisdfeld CreditAttribution: chrisdfeld commentedI 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.
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.
Comment #4
dstolHere's a new patch with support for e and P as well. I couldn't replicate problems described in #2.
Comment #5
adamdicarlo CreditAttribution: adamdicarlo commentedI 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.
Comment #6
dstolMarking as duplicate of #494434: format_date() does not support "c", "e", "P", "T" specifiers, displays GMT for all
See http://drupal.org/node/494434#comment-3409190