或者除了将日期存储为字符串之外还有其他方法吗?
// 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");
答案 0 :(得分:4)
// 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);