NSDate返回“1604”年价值? [英] NSDate return "1604" for year value?

查看:176
本文介绍了NSDate返回“1604”年价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图获取联系人的出生数据,但如果用户没有选择年份或联系人来自Facebook和年份或自己隐藏的数据,那么它会给我一年的1604值看看我在图片中的意思。

I'm try to get birth data for contacts but if user does not choose year or the contact come from Facebook and the year or the data it self is hidden so it give me the "1604" value for the year u can see what i mean in the image.

推荐答案

恭喜,您已经发现了一个实现细节!

Congratulations, you've discovered an implementation detail!

首先,联系人将日期存储为时间点,并且不可能存储没有一年的时间点,因为每个时间点都有一年。因此,必须决定地址簿如何在日期中存储未知年份。由于以下几个原因,决定1604将是一个美好的一年:

First off, Contacts stores dates as points in time, and it is impossible to store a point in time without a year, because every point in time has a year. Thus, a decision had to be made about how Address Book would store an "unknown" year in a date. It was decided that "1604" would be a fine year, for several reasons:


  1. 当你在谈论地址簿时,它是不太可能你的地址簿中有人出生于1604年。

  2. 1604是闰年(根据闰年计算的规则),这意味着如果那个你不知道出生年份的人是在2月29日出生的,那么1604也可以处理。

  3. 1604在Julian-Gregorian日历开关之前。

因此,如果你从地址簿中提取出生日期,你需要特殊情况1604作为未知年份的生日。

Thus, if you're pulling birthdates out of Address Book, you'll need to special-case 1604 as the "birthdate where the year is unknown".

注意:据我所知,只有在处理公历时才支持。对于所有其他日历,此行为未定义。

Note: To my knowledge, this is only supported when dealing with the Gregorian calendar. For all other calendars, this behavior is undefined.

这篇关于NSDate返回“1604”年价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆