简体   繁体   English

它是一种只在CloudKit中存储日期,没有时间的方法吗?

[英]Is it a way to store only date, no time in CloudKit?

I do not want to store time in CloudKit , any way to avoid it? 我不想在CloudKit存储时间,以任何方式避免它? The problem that I get date from UIDatePicker , and even dow I set only date ( dp.datePickerMode = .Date ) redundant time info will be stored in CloudKit too. 我从UIDatePicker获取日期的问题,甚至我只设置日期( dp.datePickerMode = .Date )冗余时间信息也将存储在CloudKit Red marked number was not set via date picker. 未通过日期选择器设置红色标记的数字。

在此输入图像描述

NSDate has no concept of minutes, hours, seconds, day, months, years. NSDate没有分钟,小时,秒,日,月,年的概念。 NSDate is purely a reference to a single point in time. NSDate纯粹是对单个时间点的引用。

It is only when you display a date into a readable format (like a string) that you see anything like Years, Months, Days, Hours, etc... 只有当您以可读格式(如字符串)显示日期时,您才会看到年,月,日,小时等等...

That is a product of the fact that an NSDate gets rendered into a human readable string for debugging. 这是一个事实的产物,NSDate被渲染成人类可读的字符串以进行调试。

If you don't want to show the date then don't show the date. 如果您不想显示日期,请不要显示日期。 The fact is though, someone's date of birth does actually contain hours, minutes and seconds it's just by convention that we decide to truncate it down to days only. 事实上,某人的出生日期实际上确实包含小时,分钟和秒,按照惯例,我们决定将其截短至仅数天。

Just use the NSDate and when you display it just only display the date part. 只需使用NSDate ,当您显示它时,只显示日期部分。

BTW BTW

When you don't show the time in a UIDatePicker then the current time will be used. 如果未在UIDatePicker显示时间,则将使用当前时间。

There are lots of reasons to only store a date. 有很多理由只存储日期。 Apple does not provide one. Apple没有提供。 So use an ISO - like format, 2014/06/22 in a string. 因此,在字符串中使用类似ISO的格式,2014/06/22。

Storing a time and date when you only have a date, (like a birthday or calendar day) is usually not a good practice. 存储只有日期的时间和日期(如生日或日历日)通常不是一个好习惯。 One huge pitfall of storing an NSDate when you only want a day is that you will usually get the displayed date changing depending on what time zone you show it from. 当您只想要一天时存储NSDate的一个巨大缺陷是,您通常会根据您显示的时区来更改显示的日期。 People's birthdays don't change based on timezone. 人们的生日不会因时区而改变。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM