Hi ,
I am using iggrid to display data. Date time which is stored in database is in UTC date. but there is no offset information is stored. when i fetch the data and display to user datetime should get converts automatically to the browser timezone from which user is accessing the screen. but i have a problem here is utc date is getting converting twice to UTC while diplaying. before binding the data to grid if i check my model datetimekind specififed is UTC. still conversion is happening twice. could anyone help me on this to solve.
Thanks,
Shwetha
Hello Shwetha,
Please provide me a working sample. I can't tell you what's the problem just from your explanation.
Regards,
Tsanna
Hi,
Please find the attached sample example.
here datetime are displaying in the format which I have given in the datasource. but I need the datetime should be displayed as per browser time.
I have applied dateDisplayType: "local" and enableUTCDates : false, settings.
thanks,
ShwethaigGridDisplayDatesinLocalTimezone.zip
Hello Swetha,
If you are extracting your data with EntityFramework the DateTime-s are likely getting created with DateTimeKind.Unspecified which in turn causes Newtonsoft.JSON to convert them without timezone information. Such strings are then interpreted by different browsers in different ways. For example, if you are using IE or Edge you'll get the required behavior out of the box as they take such strings as though they are in UTC format. Chrome on the other hand takes them as though they are in the local timezone.
You can work around this by telling Newtonsoft.JSON to treat DateTimeKind.Unspecified in a way that makes sense in the context of your application. If you indeed have the dates in UTC In the data base you can configure it to serialize DateTime-s like that using the following statement:
JsonSerializerSettings settings = new JsonSerializerSettings() { DateTimeZoneHandling = DateTimeZoneHandling.Utc };
JsonConvert.SerializeObject(<your data>, settings);
Then, you'll get the correct ISO format for this date making the browser's behavior unambiguous - e.g. ModifiedDate":"2018-03-11T10:01:36.827Z"
Then you need to change your column definitions for the date columns like this:
{ headerText: "Sell Start Date", key: "SellStartDate", dataType: "date", format: "dateTime", width: "*" }, { headerText: "Modified Date", key: "ModifiedDate", dataType: "date", format: "dateTime", width: "*" },
And you will not need the dateDisplayType as it defaults to local anyway.
I hope this helps!
Best regards,
Stamen Stoychev
Hi Stamen,
Not sure what changes has been added after the infragistic upgade, grid dates are displaying in local timezone. i.e data in database for created datetime column is 2007-07-11 10:24:23.733, but in the grid its displaying 7/11/2007 3:54:23 PM. as per my understanding control is thinking that value passed is in UTC and its converting to local timezone(in this example its india time, so added 5:30 hours)
I am not able to figure out what changes really working for me. however this is my requirement and I am happy that without my effort things are working. but I do need this to work only for Date Time columns not for Date columns. is there any settings to prevent this conversion for Date columns.(differentiate date and datetime)
There are no DateTime columns in igGrid. I was referring to the C# type earlier. When you specify that a column is of dataType: "date" you tell the grid to deserialize the string that it receives from the server to a JavaScript Date object. This is an actual real point of time that you can filter or sort in a natural way for objects of this type. You can then format it for the end user so that he sees only the date portion or both date and time or any other combination.