iPad Dev:将给定的日期或字符串从 SQL 转换为 NSDate

发布于 2024-09-16 12:57:09 字数 321 浏览 3 评论 0原文

我有一个应用程序,可以创建并存储具有给定开始日期的会话。用户将创建一个新的工作会话,当他们启动它时,当前时间将保存到数据库中。该应用程序需要计算工作会话开始和结束之间的时间。但是,我需要能够暂停、重新启动和继续会话,因此我需要从数据库获取日期。

假设用户在某一天上午 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

难忘№最初的完美 2024-09-23 12:57:09

看一下 NSDateFormatter

Take a look at the dateFromString: method on NSDateFormatter

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文