Reputation: 20279
Or there other ways than storing a date as string?
// read date
string dateString = NSUserDefaults.StandardUserDefaults.StringForKey ("MY_DATE");
myDate = new DateTime ();
myDate = DateTime.ParseExact (dateString, "dd.MM.yyyy", null);
// write date
NSUserDefaults.StandardUserDefaults.SetString (myDate.Value.ToString ("dd.MM.yyyy"), "MY_DATE");
Upvotes: 0
Views: 1103
Reputation: 89082
// key
NSString k = new NSString ("key");
// store a date
NSDate val = DateTime.SpecifyKind (DateTime.Now, DateTimeKind.Utc);
NSUserDefaults.StandardUserDefaults.SetValueForKey (val, k);
// retrieve a date
NSDate nsdate = (NSDate) NSUserDefaults.StandardUserDefaults.ValueForKey (k);
DateTime date = DateTime.SpecifyKind(nsdate, DateTimeKind.Unspecified);
Upvotes: 4