查找自上次用户更新 iOS 以来的时间
我正在构建一个 iOS 应用程序,用户可以输入进入当地酒吧/餐馆的预计等待时间。为了提高可靠性,我希望能够跟踪用户输入信息的时间以及 xml 文件的输入时间,然后能够将该文件解析为表视图(包含之前的更新)以供其他人查看。表格单元格将显示位置名称、大致等待时间以及输入等待时间的时间。
本质上我想弄清楚的是如何在用户更改 cel 时格式化 NSDate(我希望它看起来像一个时间,例如晚上 10:30)。给定一个时间,我如何找到当前时间和给定时间的差异?
谢谢
I am building an iOS app which users will be able to enter the estimated wait time to get into local bars/restaurants. To increase reliability, I want to be able to track when a user entered the information, and that time to an xml file and then be able to parse the file into a table view (with the previous update) for others to see. The table cell will display the name of the location, an approximate wait time, and when that wait time was entered.
Essentially what I am trying to figure out is how do I format an NSDate (I want it to look like a time for example 10:30 pm) right at the time a user changes the cel. And given a time, how do I find the difference in the current time and the given time?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那里有几个问题,没有一个与标题真正匹配,但这里是;-)
要获取当前时间/日期:
要保存它,我建议您将其存储在 NSUserDefaults 中:
再次加载日期
您可以稍后使用You 可以使用 NSDateFormatter 将日期格式化为人类可读的内容,如下所示:
您可以使用如下函数找到两个日期之间的差异:
时间间隔以秒为单位,因此要将其转换为有用的时间,您可以除以 60 以获得分钟,除以再次 60 以获得小时等。因此将其转换为人类可读的时间:
There are a few questions there, none of which really match the title, but here goes ;-)
To get the current time/date:
To save this, I suggest you store it in NSUserDefaults:
You can load the date again later using
You can format the date into something human readable using NSDateFormatter, like this:
You can find the difference between two dates using a function like this:
Time intervals are in seconds, so to convert that to a useful time, you can divide by 60 to get minutes, divide by 60 again to get hours, etc. So to convert that to a human readable time: