From the course: iOS Development Tips

Unlock this course with a free trial

Join today to access over 24,000 courses taught by industry experts.

Using Date and TimeInterval

Using Date and TimeInterval

From the course: iOS Development Tips

Using Date and TimeInterval

- [Narrator] The song says, time is on my side, but sometimes I wonder about that when trying to work with the time types in iOS. Let me show you some of the time types. In Xcode, open up a blank playground like I have here. There are two primary types for working with time, time interval and date. Add this to the playground. Var minute colon time interval equals 60.0 time interval is a length of time in seconds. Time interval is also an alias for double so you can use doubles anywhere you use time intervals. I can, for example, make another constant here for hour. And just make that 3600.0 which is 3600 seconds equals one hour. I can also do computations there, so I can do let day equal hour times 24.0 and that gives me my 86,400 seconds in a day. So that's the basics of time interval it's just pretty much a number. The simplest date representation is from the type date. You can do that with a var date equals date and you'll see that it has a date that shows up when I do that. You…

Contents