November Happy Hour will be moved to Thursday December 5th.

Trying to grasp saving UTC date and time

Vote:
 

Hi!

When upgrading our site we ran the Power Shell Script to convert datetime columns in the database to UTC-format.

We chose the following option:

Scenario 1: Development machine is in the same time zone as the site
PM> Convert-EPiDatabaseToUtc

(I ran the above cmdlet on my local machine but my local server should be in the same time zone as the live server...)

When saving a date and time to a page type, for example

testPage.MyDateTime = new DateTime(2017, 1, 11, 15, 00, 00);

it appears as 2017-01-11 16:00 in EPiServer edit mode.

Is this the desired behavior?

#173876
Jan 11, 2017 15:48
Vote:
 

Hi, Marcus,

I believe it is. The date and time gets saved as UTC, but edit mode automatically adjust it to your client settings, which is Swedish, I guess. It might be good to get a confirmation from Episerver employee though.

In earlier versions, in admin mode, UTC date/time was presented, ex. if you use scheduled jobs.

BR,

Marija

#173881
Jan 11, 2017 17:39
Vote:
 

Hello

I would agree that it is the desired behavior.

Any editor that for instance is scheduling a publish would be expecting to set it after their local time.

UTC time is great for systems, less great for people :D

#173882
Jan 11, 2017 17:45
Vote:
 

As of CMS 10 the code does ToUniversalTime on save and ToLocalTime on load, the UI diffs server time with client time and offsets accordingly. So the UI should say 15:00 in your example, I did a quick test and it seems to do as well. The behaviour of ToUniversalTime is described here: https://msdn.microsoft.com/en-us/library/system.datetime.touniversaltime(v=vs.110).aspx

CMS 9 does it slightly different. In your example DateTimeKind would be Unspecified which will be treated as UTC. You can use DateTimeKind.Local in your example to avoid that we decide what you mean with Unspecified :)

#173885
Jan 11, 2017 18:37
Vote:
 

Thanks everyone for answering!

Per: We're currently running EPiServer CMS 9 so I guess that is the reason why it appears as 16:00 and not 15:00?

Also did a test saving the datetime with DateTimeKind.Local and then I got 15:00.

Guess "everthing" will be alright after I've upgraded to CMS 10 :-)

#173892
Jan 12, 2017 9:20
Vote:
 

Is another setup in play for scheduled jobs? I have culture="sv-SE" uiCulture="sv" in Web.config but jobs that executed 14:49 have 2017-10-20 12:49:08 in the Admin UI list.

#183770
Edited, Oct 23, 2017 9:41
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.