Hi All,
Thought I would share how to set the format of a DateField object with
you. I was faced with a situation where I want to display a date in
the following format
12 January 2008
so I wanted to use the setFormat( String format) method of the
DateField object. The question was what format should I use. Initially
I tried to use a pattern as specified by the SimpleDateFormat class in
Java (
http://java.sun.com/j2se/1.5.0/docs/api/java/text/
SimpleDateFormat.html). Incidentally GWT has a class called
DateTimeFormat (
http://google-web-toolkit.googlecode.com/svn/javadoc/
1.4/com/google/gwt/i18n/client/DateTimeFormat.html) which defines a
pattern in the same fashion as the SimpleDateFormat class. So I used
the format
d MMMM yyyy
and when applied I got
12 JanJanJanJan 08080808
I have discovered however that the format to use for the DateField
object is that defined in the DateFieldDef class (
http://gwt-ext.com/
docs/gwtext1/com/gwtext/client/data/DateFieldDef.html). In my case it
was
j F Y
I hope this helps others out there who are having problems with the
date format just go to the GWT Ext javadocs and look at the
DateFieldDef class (
http://gwt-ext.com/docs/gwtext1/com/gwtext/client/
data/DateFieldDef.html). I have copied the patterns here for
convenience sake.
Format Output Description
------ ----------
--------------------------------------------------------------
d 10 Day of the month, 2 digits with leading zeros
D Wed A textual representation of a day, three letters
j 10 Day of the month without leading zeros
l Wednesday A full textual representation of the day of the
week
S th English ordinal day of month suffix, 2 chars (use
with j)
w 3 Numeric representation of the day of the week
z 9 The julian date, or day of the year (0-365)
W 01 ISO-8601 2-digit week number of year, weeks
starting on Monday (00-52)
F January A full textual representation of the month
m 01 Numeric representation of a month, with leading
zeros
M Jan Month name abbreviation, three letters
n 1 Numeric representation of a month, without
leading zeros
t 31 Number of days in the given month
L 0 Whether it's a leap year (1 if it is a leap year,
else 0)
Y 2007 A full numeric representation of a year, 4 digits
y 07 A two digit representation of a year
a pm Lowercase Ante meridiem and Post meridiem
A PM Uppercase Ante meridiem and Post meridiem
g 3 12-hour format of an hour without leading zeros
G 15 24-hour format of an hour without leading zeros
h 03 12-hour format of an hour with leading zeros
H 15 24-hour format of an hour with leading zeros
i 05 Minutes with leading zeros
s 01 Seconds, with leading zeros
O -0600 Difference to Greenwich time (GMT) in hours
T CST Timezone setting of the machine running the code
Z -21600 Timezone offset in seconds (negative if west of
UTC, positive if east)