Sitefinity time issue
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 ?
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
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 ?
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
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 ?
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();
.ToSitefinityUITime() is the new one , toLocal is obsolete