美文网首页
人/狗/码的日常 2021-05-22

人/狗/码的日常 2021-05-22

作者: 启发禅悟 | 来源:发表于2021-05-22 22:01 被阅读0次

    很多事情都是一瞬间的记忆,今天确实有几点我想写的感触,可是现在提起笔的时候,却完全忘记了。

    要是能有一个东西能把瞬间的想要记录的东西保存起来就好了。

    来总结下本周的健身状况吧,4天的目标完成。由于2/3打疫苗休息的缘故,4/5/6连续三天还是坚持下来了。为自己点赞,希望继续坚持下去。


    IMG_9DFA2348756A-1.jpeg

    酷奇越来越肥了,真的要变成胖基了。现在已经喂的相对比较少了,可是还是看着他一天天胖起来,可能是运动少了吧。以后尽量下楼的时候让他多跑一会儿。

    不知道酷奇是怎么分辨哪些能吃,哪些不能吃,很好奇这狗竟然吃花生会吐壳,吃葡萄会吐皮,你信么?

    以前老担心他吃了那些不该吃的东西,所以每次看他皮皮的在咬一些东西,我都要掰开嘴看看到底是什么,现在看来是不用担心了,连吃瓜子都会吐壳了,我还担心啥。

    今天遇到一个比较偏僻的问题,先说结论:
    NSDate类型的数据,在使用文件进行持久化之后,会损失精度。

    测试代码:

    • 创建一个日期
    • 将日期保存到字典,并把该字典保存到一个本地文件中。
    • 从文件中读取字典
    • 读取日期
        NSDate *date = [NSDate dateWithTimeIntervalSinceNow:0];
        NSTimeInterval timeInterval = [date timeIntervalSince1970];
        NSLog(@"timeInterval before saved in file is %f", timeInterval);
        
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentPath = [paths objectAtIndex:0];
        documentPath = [documentPath stringByAppendingPathComponent:@"persistance"];
        
        NSDictionary *dictToFile = @{@"date":date};
        [dictToFile writeToFile:documentPath atomically:YES];
        
        NSDictionary *dictFromFile = [NSDictionary dictionaryWithContentsOfFile:documentPath];
        NSDate *dateFromFile = dictFromFile[@"date"];
        
        NSTimeInterval dateFromFileTimeInterval = [dateFromFile timeIntervalSince1970];
        
        NSLog(@"timeInterval after saved in file is %f", dateFromFileTimeInterval);
    

    输出结果

    2021-05-22 21:52:06.135566+0800 [40977:19874631] timeInterval before saved in file is 1621691526.135535
    2021-05-22 21:52:16.000091+0800 [40977:19874631] timeInterval after saved in file is 1621691526.000000
    

    秒后面的精度丢失了。

    相关文章

      网友评论

          本文标题:人/狗/码的日常 2021-05-22

          本文链接:https://www.haomeiwen.com/subject/xzsnjltx.html