Can I use JSTL to display a date in the client’s time zone?

In Javascript, I have this function to display the current date in the header of our page:

<SCRIPT language="Javascript">
    var today = new Date();
    document.write(today.toLocaleDateString());
</SCRIPT>

I would like to do this through JSTL, but I'm not sure if this is possible. So far, I have this piece of code:

<jsp:useBean id="date" class="java.util.Date" />
<fmt:formatDate value="${date}" type="date" pattern="EEEE, MMMM dd, yyyy"/>

Since the date is now created on the server, it may not represent the date of the client. I believe that I can set the timeZone attribute of the formatDate function, but I'm not sure how to capture the client’s time zone. Can anyone suggest a suggestion?

Thanks!

+3
source share
2 answers

, , HTTP-, .

, :

  • cookie, , . , , .

  • AJAX, javascript XMLHttpRequest, "new Date" () getTimezoneOffset() , var

, - ,

+2

, , - , - javascript. ,

<script ...>document.write(<javascript to format the date>)</script>

. , , , , .

+1

Source: https://habr.com/ru/post/1708364/


All Articles