How to get current date and time from internet in iOS?


Working with date and time can be tricky, I’ve seen new programmers struggling with date and time. In almost all the application you will be required to get the date and multiple operations are dependent on it.

Here we will be seeing how to get the current date and time in swift.

In this post we will be seeing how to get the current time and UTC time.

For getting the UTC time, paste below code in playground.

let utcDate = Date()
print(utcDate)

If you wish to get the time stamp of your location, paste the below code in playground.

let dateObj = Date()
let datetformatter = DateFormatter()
datetformatter.timeZone = TimeZone.current
datetformatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
print(datetformatter.string(from: dateObj))

Updated on: 07-Aug-2019

375 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements