Saturday, 20 September 2014

Item Created time zone displays wrong programatically - SharePoint List

Recently I faced an issue, that I was having a Log field with Version enabled list. Time was being displayed correctly in the SharePoint list but while retrieving CREATED field time programactially for all versions of item, it was displaying wrong time.

I was using below statement to retrieve time for CREATED date:
version.Created.ToString("dd/MM/yyyy hh:mm tt")
My timezone was though set to +3 Region, but it was showing GMT time with +0 Regional time settings.

Then I change the above line to:

System.TimeZone.CurrentTimeZone.ToLocalTime(version.Created).ToString("dd/MM/yyyy hh:mm tt")
This done the trick for me.

Hope this helps someone!

No comments:

Post a Comment