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

Forums / Bugs & Issues / Sitefinity time issue

Sitefinity time issue

7 posts, 0 answered
  1. Arm
    Arm avatar
    5 posts
    Registered:
    01 Apr 2013
    14 Feb 2014
    Link to this post
    I have faced time issue during development with sitefinity. My TimeZone is set to utc-6 Central America. I have created a custom module  with date field. When I select time for example 12: 00 (pm). In the database it is written as 18:00(pm). That's the normal behavior I guess. So for displaying the correct time  I have found solution in forums that should work, but it doesn't 
    <%# Telerik.Sitefinity.SystemExtensions.ToSitefinityUITime(((DateTime)Eval("Date"))).ToString() %>
    It displays the same time as in the database (18:00 pm). 
    Any suggestions how to solve this problem ?
  2. Ivan D. Dimitrov
    Ivan D. Dimitrov avatar
    310 posts
    Registered:
    26 Mar 2015
    18 Feb 2014
    Link to this post
    Hi Arm,

    Can you please go to Administration->Settings->Advanced->System->UI Time Zone Config and unckeck the UserBrowserSettingsForCalculatingDates. This will add the increment of the Time Zone setting you have applied to the usual UTC time that gets stored in the database. Please go through this procedure and write back if the behavior persists. There is a possibility for that if your date field has some custom logic implemented, in which case posting the code can be beneficial towards finding a solution.

    Regards,
    Ivan D. Dimitrov
    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
  3. Arm
    Arm avatar
    5 posts
    Registered:
    01 Apr 2013
    28 Feb 2014 in reply to Ivan D. Dimitrov
    Link to this post

    Actually I am still having problem with it. See screenshots attached. I have selected 12:00pm for example, in the database it is written 8:00. 
    And here is the code I am using for displaying time . 

    ltrSessionTime.Text = SystemExtensions.ToSitefinityUITime(Item.GetValue("Date")).ToString("t");

    I am adding value to the literal during OnItemDataBound function. 

    So I need to display  12: 00 as I have selected in the beckend, not the one I have in the database with 4 hours less. 
    Any suggestions ? 

     

     

  4. Ivan D. Dimitrov
    Ivan D. Dimitrov avatar
    310 posts
    Registered:
    26 Mar 2015
    03 Mar 2014
    Link to this post
    Hi Arm,

    In order for you to get the UI time value, you need to set your date to local. Please refer to the following code:
    EventsManager eventManager = EventsManager.GetManager();
     
    var theEvent = eventManager.GetEvents().Where(q => q.Title == "asd").FirstOrDefault().EventStart.ToLocal(); // this returns the UI value
     
    var theEvent1 = eventManager.GetEvents().Where(q => q.Title == "asd").FirstOrDefault().EventStart; // this returns the Database value

    For more information on querying events, please consult our Documentation.

    Regards,
    Ivan D. Dimitrov
    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
  5. Arm
    Arm avatar
    5 posts
    Registered:
    01 Apr 2013
    03 Mar 2014 in reply to Ivan D. Dimitrov
    Link to this post

    Thanks, but I am using custom module, created with module builder.  So i don't need any event manager here. 
    The problem is with displaying time.  It always writes 4 hours less in the database, I just need to show database time + 4 hours. 
    I have searched and found ToSitefinityUITime () function, that doesn't work for me. 
    You know what I mean ?


  6. Ivan D. Dimitrov
    Ivan D. Dimitrov avatar
    310 posts
    Registered:
    26 Mar 2015
    04 Mar 2014
    Link to this post
    Hello Arm,

    The methodology for Sitefinity's dynamic modules is a bit different. Since the GetValue extension method is designed to fetch the database values, you need to alter this value yourself in order for it to get associated as a time value. This is done by casting the value you get to date time, more specifically, to a nullable datetime value, as the database entry is nullable. Please review the code snippet below for further reference:
    DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
    Type MyType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.MyModule.ModuleItem");
     
                var myCollection = dynamicModuleManager.GetDataItems(MyType).FirstOrDefault();
     
                var correcttime = myCollection.GetValue("DateField") as Nullable<DateTime>;
                if (correcttime != null)
                {
                    //This returns the UI time. You can set it to string if needed
                    var asd = correcttime.Value.ToLocal();
                }


    Regards,
    Ivan D. Dimitrov
    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
  7. Bishoy
    Bishoy avatar
    27 posts
    Registered:
    15 Aug 2013
    03 Sep 2014
    Link to this post

    .ToSitefinityUITime() is the new one , toLocal is obsolete

7 posts, 0 answered