1

Actually my database resides at CST time zone and all the datatime value are stored in CST only. In one of my application screen, we are showing the datetime value among with other columns. while loading the data into grid it is showing properly but whenever i try to sort the grid with any of the column, The datetime column in showing in UTC rather than CST.

EntityMapper.MapList<TestsModelMapper>(response.TestEntity, TestModel);
JavaScriptSerializer jsSerializer = new JavaScriptSerializer();

SearchedTestHiddenField.Value = jsSerializer.Serialize(TestModel);
string jsonString = SearchedTestHiddenField.Value;

JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
IList<TestsModel> TestModel = (IList<TestsModel>jsSerializer.Deserialize(jsonString,typeof(IList<TestsModel>));
Fran
  • 6,440
  • 1
  • 23
  • 35
vinoth
  • 27
  • 5
  • I would recommend you to use [Json.Net](https://www.newtonsoft.com/json) over the serializer from .Net lib. More about this issue you can read [here](https://stackoverflow.com/questions/17069460/javascriptserializer-utc-datetime-issues) – OlegI Nov 03 '17 at 13:58
  • As explained in the [docs](https://msdn.microsoft.com/en-us/library/bb299886.aspx#intro_to_json_sidebarb), `JavaScriptSerializer`: *the ASP.NET AJAX team made a change for the final release to address this problem by adopting the **"\/Date(ticks)\/"** format* for `DateTime` where *ticks represents the number of milliseconds since January 1, 1970 in Universal Coordinated Time (UTC).* – dbc Nov 03 '17 at 17:16
  • If want to use `JavaScriptSerializer` you will need to convert from Microsoft's format to the desired time zone on the client side. Can you share the code that shows how you are formatting the dates currently in your application screen? – dbc Nov 03 '17 at 17:18
  • Thanks for your comments. Actually we are serializeing the model and assigning it to hidden field and the value of hidden field is assigning to string and deserialize it and assigning back model.Please the below model public class TestsModel { public Int64 WLogID { get; set; } public Int64 WID { get; set; } public DateTime TestDate { get; set; } } – vinoth Nov 06 '17 at 14:35

0 Answers0