Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
324 views
in Technique[技术] by (71.8m points)

c# - Good way to store and read timestamp in Windows Phone

I am working on a windows phone app.

Just want to ask for some suggestion. Here is the problem:
I want to store a time in somewhere and use the time to check if I need an internal file update. (if my file has not been updated in 60 days, update it. something like this)

I am not sure if I can have access to the registry directly in the app. and the other possible way to solve the problem is maybe save the timestamp to a file in isolated storage. But I dont have a lot idea about how to save it in a easy to use format and how to read it again.

Any suggestions about saving timestamp?

Thank you

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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();
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...