Grails - Date display based on timezone user

I know that I need to set TimeZone somewhere, but I don’t know how I can “get” the current TimeZone from the user and display (dynamically?) The date with the correct offset.

This is my code:

Domain:

class MyClass {

  Date myDate

}

Controller:

def unixSeconds = 1386760029
Date date = new Date(unixSeconds*1000L)

GSP:

<g:formatDate format="yyyy-MM-dd HH:mm" date="${MyClassInstance.myDate}" timeZone="${TimeZone.getTimeZone("GMT")}"/>
+4
source share
1 answer

You cannot have the user's time zone, because this information is not sent in the request.

You can try to get the user's location using Geolocation or GeoIP to get the user’s country, and then set the appropriate time zone.

- UTC Local Time, JavaScript getTimezoneOffset():

var d = new Date()
var n = d.getTimezoneOffset();

.

+2

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


All Articles