Skip to main content

Daniel's Blog

Go Search
Daniel's Blog
About
Book Reviews
Search
The SharePoint Experience though Windows 7
  

Daniel's Blog > Posts > Having problems when converting a list items Date Time string to a DataTime object?
Having problems when converting a list items Date Time string to a DataTime object?

This afternoon I was trying to covert a string representation of a list Items EventDate value. But without much luck.

image

As you can see, no matter how I converted it, it would add an additional 9.5 Hours to it. 9.5 Hours of the GMT offset for Adelaide, Australia.

The solution, Take out the ā€œZā€ on the end.

DateTime EventDate = Convert.ToDateTime(this.Item[EventDateFieldName].ToString().Replace("Z", ""));

This will stop the adding of an additional GMT offset to the DateTime object and can be used anywhere you see the ā€œZā€ in any of your datetimes!

Comments

There are no comments yet for this post.