Date format gotcha

Here is a gotcha to watch out for. I just noticed this while I was looking into a bug about why dates in the grid were offset from the dates in the database.

In the java and ColdFusion date formatters you use the letter H to represent the hour in 0-23 hour format. However in the flex date formatter (which we use for flash forms) H represents the hour in 1-24 format not the 0-23 format that I was used to. In flash you need to use the letter J for the 0-23 format in a date mask.

So if you run into the problem where your dates are displayed 1 hour off, remember to use J instead of H in the mask attribute.

Here are all the flex dateFormatter mask characters.


Valid pattern letters include:
Y - Year.
M - Month.
D - Day in month.
E - Day in week.
A - AM/PM indicator.
J - Hour in day (0 to 23).
H - Hour in day (1 to 24).
K - Hour in AM/PM (0-11).
L - Hour in AM/PM (1-12).
N - Minute in hour.
S - Second in minute.

Date Formatter doc

Comments
Josef Falletta's Gravatar I am having this very same problem with a CFInput field. Could you show me where to use the "J" when trying to format the time for 0-23hrs. Is it within the CFInput or some where before?
Thanks for your Help
# Posted By Josef Falletta | 10/4/05 5:07 AM
Panos's Gravatar Thanks a lot for the gotcha! You really saved my day :)
# Posted By Panos | 10/20/09 7:51 AM
Paul's Gravatar Thanks. This is the first blog post I saw which lists the format patterns. Even the livedocs doesn't cover date formatting this well. :)
# Posted By Paul | 11/23/09 11:23 PM
Paul's Gravatar Would you know why sometimes the formatter displays this value?

01/00/N 12:00 AM

I'm using this format below:

MM/DD/YY L:NN A
# Posted By Paul | 11/23/09 11:27 PM