iPad Dev:将给定的日期或字符串从 SQL 转换为 NSDate
我有一个应用程序,可以创建并存储具有给定开始日期的会话。用户将创建一个新的工作会话,当他们启动它时,当前时间将保存到数据库中。该应用程序需要计算工作会话开始和结束之间的时间。但是,我需要能够暂停、重新启动和继续会话,因此我需要从数据库获取日期。
假设用户在某一天上午 10:30 开始工作,并继续工作直到中午 12:30。假设他们出于某种原因需要关闭应用程序并返回工作会话。会话需要计算并显示自开始以来当前经过的时间。所以,我想创建一个 NSDate 对象,其开始时间从数据库中获取......但我不能。至少,我找不到用字符串甚至一组参数初始化 Date 对象的方法。我确信有一种方法可以做到这一点,但我找不到。
I have an app that creates and stores a session with a given start date. The user would create a new work session and when they start it, the current time would get saved to the database. The app needs to count time between the start and end of a work session. However, I need to be able to pause, restart, and continue sessions, so I need to get the date from the database.
Say a user starts at 10:30am on a particular day and continues their work session until 12:30pm. Say they need to close the app for whatever reason and come back to the work session. The session needs to count and show the current elapsed time since the beginning. So, I wanted to make an NSDate object with the start time taken from the database...but I can't. At least, I can't find a way of initializing a Date object with a string or even a set of parameters. I'm sure there's a way to do it, but I can't find one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看一下
NSDateFormatter
Take a look at the
dateFromString:
method onNSDateFormatter
您可以从此处的Apple Doc开始
http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html#//apple_ref/doc/uid/TP40002369-SW1< /a>
可以输入示例,但我认为文档包含一些
you can start with the Apple Doc here
http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html#//apple_ref/doc/uid/TP40002369-SW1
could type up examples, but I think the documentation contains some