如何以编程方式在 nsdate 中设置小时分钟?
我在一个标签中有 2:01:20 PM 格式;经过一些计算,我需要更改该标签的小时和/或分钟。
也就是说,是否可以通过将其转换为 NSDate 对象并修改小时和分钟(如 3:20:30 PM)来更改该标签值?
有没有这方面的设置方法?
I have 2:01:20 PM format in one label; after some calculations, I need to change the hour and/or minute of that label.
That is ,Is it possible to change that label value, by converting it as NSDate object and modifying hour and minute like 3:20:30 PM?
Are there any setter methods for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
第一个问题的答案“如何以编程方式在 nsdate 中设置小时分钟?”
如下:
The answer to your first question "how to set hour minute in nsdate programatically?"
is following:
如果您需要及时计算特定的真实实例,例如 2010 年 10 月 23 日下午 3:20:30,那么您需要使用 NSCalendar,它可以让您分解日期并进行与日期相关的计算。
警告的话。日期和时间的计算极其复杂和详细。预计需要花费几个小时来学习 API。
If you need to calculate specific real instances in time e.g. 3:20:30 PM Oct 23, 2010, then you want to use NSCalendar which lets you decompose dates and do date related calculations.
Word of warning. Date and time calculations are surprisingly complex and detailed. Expect to spend a couple of hours learning the API.