
- iOS Tutorial
- iOS - Home
- iOS - Getting Started
- iOS - Environment Setup
- iOS - Objective-C Basics
- iOS - First iPhone Application
- iOS - Actions and Outlets
- iOS - Delegates
- iOS - UI Elements
- iOS - Accelerometer
- iOS - Universal Applications
- iOS - Camera Management
- iOS - Location Handling
- iOS - SQLite Database
- iOS - Sending Email
- iOS - Audio & Video
- iOS - File Handling
- iOS - Accessing Maps
- iOS - In-App Purchase
- iOS - iAd Integration
- iOS - GameKit
- iOS - Storyboards
- iOS - Auto Layouts
- iOS - Twitter & Facebook
- iOS - Memory Management
- iOS - Application Debugging
- iOS Useful Resources
- iOS - Quick Guide
- iOS - Useful Resources
- iOS - Discussion
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 Articles
- 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 can I set an icon for my iOS application?
- How do I programmatically “restart” an iOS app?
- Current Date and Time in Perl
- How do I get the current time zone of MySQL?
- How to get the current date and time in Java?
- How to get current time and date in C++?
- How to get current date and time in Python?
- How to get current date and time in JavaScript?
- How to display date and time picker in ReactNative?

Advertisements