为什么这个日期处理不正确?
我有这样的代码:
currentMinuteInt = [[cal components:NSHourCalendarUnit
fromDate:tuesdayAlarmTime] minute];
它应该输出“15”,但输出“-2147483587”。我认识到有时会显示与日期相关的奇怪数字,但我不明白为什么会在这里发生。
我计算时间的代码是:
hours = [[cal components:NSHourCalendarUnit fromDate:now] hour];
并且工作正常。 tuesdayAlarmTime 是一个完整的日期,其分钟部分是“15”。
I have this code:
currentMinuteInt = [[cal components:NSHourCalendarUnit
fromDate:tuesdayAlarmTime] minute];
which should have outputted '15', but instead outputted '-2147483587'. I recognise this weird sort of number being shown sometimes in relation to dates, but I can't figure out why it's happening here.
The code i have for working out the hour is:
hours = [[cal components:NSHourCalendarUnit fromDate:now] hour];
and that works correctly. tuesdayAlarmTime is a full length date, and the minute part of it is '15'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
难道不应该吗
Shouldn't it be
使用
[cal Components:NSHourCalendarUnit fromDate:tuesdayAlarmTime]
,您的NSDateComponents
对象仅包含一个小时值,没有其他内容。相反,您必须使用:With
[cal components:NSHourCalendarUnit fromDate:tuesdayAlarmTime]
, yourNSDateComponents
object only contains an hour value, nothing else. Instead, you must use: