MY mENU


Tuesday 29 May 2012

Formatting date with fmt:formatDate Action


Date and time are important matters in internationalized web applications. Different country has it own way to present date and time in different format. JSP has an action called to allow you to format date and time based on a specificlocale. Here is a table of action attributes. As you can see only value attribute isrequired for action.

Date and time are important matters in internationalized web applications. Different country has it own way to present date and time in different format.  JSP has an action called  to allow you to format date and time based on a specificlocale. Here is a table of action attributes. As you can see only value attribute is required for action.
Attributes
NameMandatoryMeaning
valueyesDate and/or time value to be formatted.
typenoAccept date or/and time to be used to format
dateStylenoSpecify predefined formatted style for date only if date value is used for formatting.
timeStylenoSpecify predefined formatted style for time only if time value is used for formatting.
patternnoSpecify standard customized pattern for formating date and/or time
timeZonenoIf the time value is used to format, this attribute specify time zone for that time value.
varnoThis attribute is for exporting scoped  variable which stores the formatted date and/or time as a string
scopenospecify the scope of var.

Let's take a look at an example of using  action to format date in different locale.
First we use the useBean tag to initialize a scoped variable called now and store current date value into this variable. Then we set the locale to different locales: US and FR and print out the current date in now variable by using  action.

Formatting Date and/or Time

By default format and print only date. If you want to print time or bothdate and time you can use the type attribute. The type attribute accepts date, time and both to allow you to print such a this information in a specific locale. Let's take a look at an example:
Formatting Date Time with predefined styles and custom patterns
You cannot only format and print date & time with predefined styles provided by JSTL but also with a custom pattern. The timeStyle and dateStyle attributes of specify the predefined styles you want to format. Patterns attribute enables you to define your own style. In this case, you need the date & time code table bellow to find exactly what you want to format.
CodeMeaning
GThe era (A.D., B.C., and so on)
yThe year (yy for two-digit years, yyyy for four digits)
MThe month (MM for numeric month, MMM or longer for month names orabbreviations)
wThe week of the year (ww for two digits)
WThe week of the month
DThe day of the year (DDD for three digits)
dThe day of the month (dd for two digits)
FThe numeric day of the week
EThe text day of the week (EEEE or longer for full name)
aAMa.m./PMp.m. indicator
HHour of the day (0–23)
kHour of the day (1–24)
KHour in a.m./p.m. (0–11)
hHour in a.m./p.m. (1–12)
mMinutes in hour
sSeconds in minute
SMilliseconds in second
zFull time zone name
ZRFC 822 time zone (for example, 0500)
Here is an example of using predefined styles and custom pattern to format and print date & time.

9 comments:

Jacob Swanner said...

Well I am so excited that I have found your post because I have been searching for some information on this for almost three hours! You've helped me a lot indeed and by reading this article I have found many new and useful information about this subject! http://scarprinnow.com

Mike Perham said...

Thanks for the post and information! I think education is important for us so we must prepare the best education for our generation by sharing such great information with each other!
http://celabright.info

Unknown said...

I have to say this post was certainly informative and contains useful content for enthusiastic visitors. I will definitely bookmark this blog for future reference and further viewing. Thanks a bunch for sharing this with us!
www.fadeplex.com

Unknown said...

I came to this page by searching Yahoo. I have found it quite interesting. Thank you for providing this. I will have to visit here again!
we buy houses

Houston plastic surgeon said...

I appreciate the work of all people who share information with others. Great Blog! Great post about this. I am sure my visitors will find that very useful. This is an interesting and so well maintained blog. Whole article is too good and well written.

Houston plastic surgeon

SEO said...

Really enjoyed reading this. Thank you for sharing this valuable information with us. I have bookmarked this site and will be sure to check for updates.
latest indian sarees

furniture online outlet said...

i do pretty much the exact same thing, local vhosts and all. taking nightly backups of /home is easy with rsync, so when anything goes awry, i just pull down the folder from my vps. since the cronjob itself is in the folder, even my backup script gets backed up. what ide do you use?

Unknown said...

This is such an informative article and very clearly written. Every single thought and idea is direct to the point. Perfectly laid out. Thank you for taking your time sharing this to you readers.
Fast House Sale San Antonio

Buy jodhpuri suits said...

I adore what you have got right here. You make it entertaining and you still manage to keep it smart.This is truly a great blog thanks for sharing

Post a Comment