Search code examples
javascriptjavadategrailsgsp

I have an issue with saving date and time?


$(document).ready(function(){
    var timezone = jstz.determine_timezone();
    var clientTimeZone=timezone.name();
    document.getElementById("clientTimeZone").value = clientTimeZone
});

Using the Above Code in gsp to get the current timeZone of User but it is not working properly?.

Actually server is north Virginia , on saving i getting an +6:30 hours issue .But in local it's working properly .

Below code is used in Services.

 def  clientTimeZone = clientTimeZone == null  ? "Asia/Kolkata" : clientTimeZone
TimeZone tz = TimeZone.getTimeZone(clientTimeZone);
def clientDateFormate = new SimpleDateFormat('dd/MM/yyyy hh:mm a')
clientDateFormate.setTimeZone(tz)
database.xyz=clientDateFormate.parse(curDate)

Solution

  • I solved it.

    I was able to save it correctly be using the UTC date/time in milliseconds, rather than a specific time zone.

    To load the date/time I simply formatted it as a UTC date/tine in milliseconds, and it worked perfectly.

    Issue solved :)