[CLOSED] JSON is using the user's current time zone when converting a DateTime

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] JSON is using the user's current time zone when converting a DateTime

    I found an issue regarding the DateTime conversion by Json. I have a GridPanel with a date column but when i run the example my current time zone is -3:00 (Brazil) is applied to the value of date column.

    Click image for larger version. 

Name:	ex00001.png 
Views:	73 
Size:	19.8 KB 
ID:	6153

    It was supposed to be 09:14:..

    Note: i found another thread regarding this issue, but i think that it's incomplete: http://forums.ext.net/showthread.php...-Date-Timezone

    1 - View
    <ext:GridPanel ID="GridPanel1" runat="server" Title="Records">
        <Store>
            <ext:Store runat="server" ID="Store2">
                <Proxy>
                    <ext:AjaxProxy Url="/Example/LoadFakeRecords/">
                        <ActionMethods Read="POST" />
                        <Reader>
                            <ext:JsonReader Root="data" />
                        </Reader>
                    </ext:AjaxProxy>
                </Proxy>
                <Model>
                    <ext:Model ID="Model2" runat="server">
                        <Fields>
                            <ext:ModelField Name="ID" Type="String" />
                            <ext:ModelField Name="Name" Type="String" />
                            <ext:ModelField Name="Birthdate" Type="Date" DateFormat="d/m/Y H:i:s">
                                <Convert Handler="return Ext.util.Format.date(value, 'd/m/Y H:i:s');" />
                            </ext:ModelField>
                        </Fields>
                    </ext:Model>
                </Model>
            </ext:Store>
        </Store>
        <ColumnModel ID="ColumnModel1" runat="server">
            <Columns>
                <ext:RowNumbererColumn ID="RowNumbererColumn1" runat="server" />
                <ext:Column ID="Column1" runat="server" Text="ID" DataIndex="ID" />
                <ext:Column ID="Column3" runat="server" Text="Name" DataIndex="Name" />
                <ext:Column ID="Column2" runat="server" Text="Birthdate" DataIndex="Birthdate" />
            </Columns>
        </ColumnModel>
    </ext:GridPanel>
    2 - Controller
    public class ExampleController : System.Web.Mvc.Controller
    {
        public ActionResult Index()
        {
            return View();
        }
    
        public StoreResult LoadFakeRecords()
        {
            List<Person> lst = new List<Person>();
    
            for (int index = 0; index < 15; index++)
            {
                lst.Add(new Person
                {
                    ID = index,
                    Name = "Name" + index,
                    Birthdate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, index)
                });
            }
    
            return new StoreResult(lst, lst.Count());
        }
    }
    3 - Utility
    public class Person
    {
        public int ID { get; set; }
    
        public string Name { get; set; }
    
        public DateTime Birthdate { get; set; }
    }
    Thanks in advance
    Last edited by Daniil; May 06, 2013 at 4:03 AM. Reason: [CLOSED]
  2. #2
    Try to set in web.config
    dateTimeZoneHandling="RoundtripKind"
    or in Global.asax
    JSON.GlobalSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.RoundtripKind;
  3. #3
    Unfortunately, i was not able to find any source that explain how to make that configuration in the Web.Config.

    In Global.asax it works perfectly.
    Last edited by RCN; May 03, 2013 at 1:19 PM.
  4. #4
    Sorry Vladimir, i thought it worked but it didn't. To accomplish it, it's necessary to do the following in the Global.asax:

    Ext.Net.JSON.GlobalSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Local;
    Last edited by RCN; May 06, 2013 at 11:27 AM.
  5. #5
    Hi,

    I was able to reproduce the problem in IE9 and Chrome, but not in FireFox.

    I can confirm that DateTimeZoneHandling.Local appears to help remedy the problem,the RoundtripKind setting doesn't.

    Quote Originally Posted by RCN View Post
    Unfortunately, i was not able to find any source that explain how to make that configuration in the Web.Config.
    Just in the "extnet" section.
    <extnet dateTimeZoneHandling="Local" />
  6. #6
    Thank you Danill
  7. #7

    Is there anything like this for Web Forms

    Quote Originally Posted by RCN View Post
    Sorry Vladimir, i thought it worked but it didn't. To accomplish it, it's necessary to do the following in the Global.asax:

    Ext.Net.JSON.GlobalSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Local;
    I tried this (web.config option) in my Web Forms site. I got an error stating that the attribute was unrecognized.
  8. #8
    Please try to add the following code into your Global.asax

    protected void Application_Start()
    {
        Ext.Net.JSON.GlobalSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Local;
    }
  9. #9
    Quote Originally Posted by RCN View Post
    Please try to add the following code into your Global.asax

    protected void Application_Start()
    {
        Ext.Net.JSON.GlobalSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Local;
    }
    I'm getting an error "GlobalSettings is not a member of Ext.Net.JSON"
  10. #10
    you must update from SVN
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 2
    Last Post: Dec 22, 2011, 2:45 PM
  2. [CLOSED] Time zone for time in UTC
    By krzak in forum 1.x Legacy Premium Help
    Replies: 11
    Last Post: Jun 01, 2011, 1:56 PM
  3. [CLOSED] Different time zone settings on DateFields
    By georgek in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Nov 04, 2010, 1:40 AM
  4. [1.0] - JSON Serialize DateTime Request
    By drkoh in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Jul 26, 2010, 1:56 PM
  5. [CLOSED] [1.0] Json Webservice DateTime Parsing Error
    By webclouder in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Jun 04, 2010, 1:10 AM

Posting Permissions