We have a server in UK, and our clients are in US with different timezones.
In a grid, we set up a datetime field with default value as datetime.now in the cshtml view file. However, we found the issues:
1. The datetime.now is server datetime, not client datetime, so it is always wrong. how can we use the users datetime value?
2. we have tried using onsave event with gridrow.isnew() to set client's default value. however, if the user change the value, the isnew() is still return true which overwrites user's new input.
Thanks
9 Answers, 1 is accepted
In order for the dates to be validated and updated correctly you need to ensure that you set matching cultures on the server and on the client. Please examine the following thread that describes how you can ensure that the cultures on the server and client are the same.
Regards,
Viktor Tachev
Telerik by Progress

Hi Viktor,
We cannot set up the cultures for the server side because this is a global app. The reason is that, the datetime.toString is depending on the user's login culture setting. eg.
- user A is in UK, it is "31 Dec 2016" and the timezone is in UK
- user B is in Japan, it is "2016/12/31" and the timezone is in Japan
- user C is in US, it is "12/31/2016" and the timezone is depending on their states (computer time)
- user D is from US, it is "12/31/2016" but he is traveling around different timezone.
Currently, we have a patch process in cshtml to format the datetime correctly based on user's culture profile. However, when we use .default(DateTime.Now) in the kendogrid column setting, the value is not right for the users in a different timezone. The user want to see their machine time instead of server's current time. How can I make new added column using the user's machine time? (as I describe earlier, I use onSave to trigger JS by checking gridrow.isnew(). However, if I have 3 rows new rows, all values are changed . I want the only added row to be changed for user's current time.
In that case you should set the culture as described in the Per-request setup section of the article. Override the Initialize method for the controller and set the appropriate culture that will be used.
Regards,
Viktor Tachev
Telerik by Progress

thanks
However, how does this help us to get the client current datetime value by culture for new row?? I am in California and in new York are the same culture but different time values.
In that case you can keep the dates in the database in UTC format. You should convert the time manually before sending it to the server to ensure that is stored in the correct format.
Please check out the following example that illustrates the approach:
Also, examine the thread below that discusses similar behavior.
Regards,
Viktor Tachev
Telerik by Progress

Hi Viktor,
yes, we have all UTC set up correct ly, the only issue is the value
for example, in cshtml , we use default datetime.now do one column, the UK users see the value for the new row is California web server current time value.
Eg, the web server is 5:55 now in US, but UK is 17:55 already, but he still see 5:55 in his machine, when he creates a new record.
Thanks


well.. I needed that feature now.. so I end up hacking it in the JS, but still looking for a better way (in cshtml) instead of hacking the default value afterwards in JS.
if (e.model.isNew() == true && e.model.isNewInerted == null) { //replace to use the client Now
e.model.isNewInerted = false;
e.model.appointmentDatetime= Date.now();
}
In order to use the user's local time you need to use client-side logic to create the date. Note that each JavaScript Date object is created with timezone offset by default. Then, you need to account for that offset and adjust the time before sending the data to the server.
Regards,
Viktor Tachev
Telerik by Progress