Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DateTimeZone to/from database

Tags:

c#

nodatime

I'm trying to get a handle on using the Noda Time framework by Jon Skeet (and others).

How do I store the DateTimeZone and retrieve it from the database. I thought the Id property value might be the one to set to the database, but how do I create a DateTimeZone from the Id since DateTimeZone is an abstract class?

like image 607
Chuck Savage Avatar asked Jan 25 '13 22:01

Chuck Savage


1 Answers

Storing the ID is fine, and you'd get it back using the relevant IDateTimeZoneProvider and its indexer, normally retrieved via DateTimeZoneProviders. For example:

var london = DateTimeZoneProviders.Tzdb["Europe/London"];

You do need to know which provider you used, of course - IDs are only scoped to the provider, effectively.

like image 184
Jon Skeet Avatar answered Sep 19 '22 09:09

Jon Skeet