{ "id": 1234, "name": "John Doe", "lastModified": "2012-03-03 14:40"}The interesting part in this scenario is the last modified date, returned in the format "yyyy-MM-dd HH:mm" in GMT time.
The service itself is quite old and we hadn't had any problems with it until a new client was being developed and wanted to use this service. When the new client was hitting the service it was returning the wrong date format.
The JSP view had the following:
{ "id": ${object.id}, "name": ${object.name}, "lastModified":<fmt:formatedate pattern="yyyy-MM-dd HH:mm" values="${object.lastModified}" /> }Digging through apaches implementation of the tag I found something interesting.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create formatter | |
Locale locale = SetLocaleSupport.getFormattingLocale( | |
pageContext, | |
this, | |
true, | |
DateFormat.getAvailableLocales()); | |
if (locale != null) { | |
//..... | |
} else { | |
// no formatting locale available, use Date.toString() | |
formatted = value.toString(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Enumeration getRequestLocales(HttpServletRequest request) { | |
Enumeration values = request.getHeaders("accept-language"); | |
if (values.hasMoreElements()) { | |
// At least one "accept-language". Simply return | |
// the enumeration returned by request.getLocales(). | |
// System.out.println("At least one accept-language"); | |
return request.getLocales(); | |
} else { | |
// No header for "accept-language". Simply return | |
// the empty enumeration. | |
// System.out.println("No accept-language"); | |
return values; | |
} | |
} |
No comments:
Post a Comment