To save, just use a .ToString() on the date as you write it to isolated storage.
To revive it as a date, read it out as a string, then parse it using the DateTime class.
string inbounddate = OurHelperMethodReadStringFromIsolatedStorage();
DateTime newdate = DateTime.Parse( inbounddate );
An example is below. m_Helper is a utility class I have for reading and writing strings to isolated storage.
private void Button_GetTimeNow_Click(object sender, RoutedEventArgs e)
{
TextBlock_Now.Text = DateTime.Now.ToString();
}
private void Button_SaveTimeToISO_Click(object sender, RoutedEventArgs e)
{
m_Helper.WriteFile(TextBlock_Now.Text);
}
private void Button_GetTimeFromISO_Click(object sender, RoutedEventArgs e)
{
TextBlock_FromISO.Text = m_Helper.ReadFile();
DateTime _loaded = DateTime.Parse( TextBlock_FromISO.Text );
TextBlock_Output.Text = _loaded.ToLongDateString();
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…