Wrong time displayed in Custom Widget

Posted by Community Admin on 04-Aug-2018 16:05

Wrong time displayed in Custom Widget

All Replies

Posted by Community Admin on 12-Mar-2014 00:00

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

Posted by Community Admin on 17-Mar-2014 00:00

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
 

This thread is closed