Java – JSP – date format and Google cache

I want to display the formatted date on the JSP page, so I use:

<fmt:formatDate pattern="MMM d" value="${myEvent.date}"/>

It works perfectly It appears on the page as

Nov 28

However, something strange happens when Google caches it - the date on the cache page is shown as follows:

2016-11-28 20:00:00.0

Who can explain? Shouldn't it be formatted on the server? Does my application server (Tomcat) only send HTML to pages? How does Google know this is actually a Java date?

Just to clarify, in order to enter the cached version of the page, I perform a search on Google, display my page in the search results, and then click the down arrow to go to the cached version of my page

Solution

Obviously, if a JSP is requested without the "accept language" HTTP header, the JSTL formatdate tag does not format the date, but returns the result of tostring() of the date object

You can verify this by using curl to get the page source (instead of viewing the page source in chrome)

Conclusion: if you use the JSTL formatdate tag and want to format the date in Google's cache, you should explicitly set the locale For example:

<fmt:setLocale value="en_US" />

I hope it can help others

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>