+1-888-365-2779
Try Now
More in this section

Forums / Bugs & Issues / Wrong time displayed in Custom Widget

Wrong time displayed in Custom Widget

2 posts, 0 answered
  1. Dustin
    Dustin avatar
    20 posts
    Registered:
    05 Jan 2012
    12 Mar 2014
    Link to this post

    I can't seem to get the correct time displayed in a Custom Widget. 

    I created a User Control with a RadGrid and have it registered and working well on the frontend...But one of the columns that displays a datetime is still showing the UTC time in the database and not the timezone that I thought it would be displaying. 

    I have pacific time set (-8 UTC) under settings and the checkmark checked in "UI Time Zone Config" under Settings->Advanced->System. Changing either of these doesn't seem to change the  custom widget datetime though

    In the radgrid's ItemDataBound I get the datetime from the column and convert it using ToSiteFinityUITime but it is still in UTC format when the page is displayed.

            protected void userHistoryGrid_ItemDataBound(object sender, GridItemEventArgs e)
            {
                if (e.Item is GridDataItem)
                {
                    GridDataItem item = e.Item as GridDataItem;
                    DateTime utcTime = Convert.ToDateTime(item["lastlogindate"].Text);
                    DateTime correctTime = Telerik.Sitefinity.SystemExtensions.ToSitefinityUITime(utcTime);
                    item["lastlogindate"].Text = correctTime.ToString("F");
                    //item["lastlogindate"].Text = "You at least made it here";
                }
            }

    and I do realize I could just -8 the hours for a quick fix...but I didn't know if this was a bug or no. 

    ​any help would be great! thanks

  2. Junior Dominguez
    Junior Dominguez avatar
    115 posts
    Registered:
    08 Dec 2016
    17 Mar 2014
    Link to this post
    Hi Dustin,

    You will need to subscribe to the method ItemDataBound instead of ItemCreated. It may look like this :

    void UsersList_ItemDataBound(object sender, GridItemEventArgs e)
            {
                if (e.Item is GridDataItem)
                {
                    GridDataItem item = e.Item as GridDataItem;
                    DateTime localTime = (item.DataItem as User).LastLoginDate.ToLocalTime();
                    item["lastLoginDate"].Text = localTime.ToString();
                     
                }
            }


    Kind Regards,
    Junior Dominguez
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
2 posts, 0 answered