Core JSTL[c] Mastering the JSP Standard Tag Library
Topics in This Chapter
If you want your website to be accessible to as many people as possible, it's crucial to localize text, as discussed in "I18N Actions" on page 248. But it's just as important to localize numbers, dates, and currencies; for example, if you publicized an event on your website and you specified the date as 06/12/2004, Americans would arrive on June 12th, whereas most Europeans would arrive on December 6th. Fortunately, JSTL provides six actions that you can use to format and parse numbers, currencies, percents, and dates:
The first two actions listed above<fmt:formatNumber> and <fmt:parseNumber>are the inverse of one another. The <fmt:formatNumber> action formats a numeric value, which you can specify as either a string or an instance of java.lang.Number , and outputs that numeric value as a string. The <fmt:parseNumber> action accepts a string representing a formatted number and parses that string into an unformatted numeric value (an instance of java.lang.Number ). The <fmt:formatDate> and <fmt:parseDate> actions are also the inverse of one another. The <fmt:formatDate> action formats an instance of java.util.Date and outputs a string, whereas <fmt:parseDate> accepts a string representing a formatted date and parses that string into an instance of java.util.Date . You can use the formatting and parsing actions together to manipulate numeric values; for example, you could:
The last two actions listed above<fmt:timeZone> and <fmt:setTimeZone>let you establish a time zone for the <fmt:formatDate> and <fmt:parseDate> actions. See "Using Time Zones" on page 343 for more information about time zones and the time zone actions. |