

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do I display the current date and time in an iOS application?
Playing with date and time is very important in any programming language, it becomes more important if you’re developing mobile application.
Numerous application such as weather, forecast, gaming and so on uses date and time. In this we will be seeing how we can get the current date and time.
To get the current date and time we will be using timeIntervalSince1970 instance property, you can read about it https://developer.apple.com/documentation/foundation/nsdate/1407504-timeintervalsince1970
So copy the below code in your viewDidLoad method and run the application, we will be printing the current date and time, and based on requirement we can print the same in UILabel in storyboard.
override func viewDidLoad() { super.viewDidLoad() let timestamp = NSDate().timeIntervalSince1970 let timeInterval = TimeInterval(timestamp) let currenTime = NSDate(timeIntervalSince1970: TimeInterval(timeInterval)) print(currenTime) }
- Related Questions & Answers
- How do I display the current date and time in an Android application?
- How do I get the current date and time in JavaScript?
- How to get current date and time from internet in iOS?
- Java Program to Display current Date and Time
- How can I get the current time and date in Kotlin?
- How do I get the current date in JavaScript?
- How do I get the current time zone of MySQL?
- Current Date and Time in Perl
- How can I set an icon for my iOS application?
- How to get the current date and time in Java?
- How to get current date and time in Python?
- How to get current date and time in JavaScript?
- How to get current time and date in C++?
- How to get the current local date and time in Kotlin?
- Get current time and date on Android
Advertisements