DateFormatter | Swift Programming Tutorial | Absolute Beginner

Опубликовано: 02 Август 2026
на канале: AmandeepSingh
24
3

📱 Welcome to my channel - Your Ultimate Destination for iOS Development! 🚀

🔍 Explore the World of iOS Development with Amandeep Singh!

We will cover DateFormatter in this tutorial :-

In Swift, DateFormatter is a class that allows you to convert between Date objects and string representations of dates. It provides a way to format and parse dates according to a specified format string

This is the function to convert string to Date.
func convertStringtoDate(strDate: String) {
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale(identifier: "en_US_POSIX") // set locale to reliable US_POSIX
dateFormatter.dateFormat = "yyyy-MM-dd hh:mm a"
if let date = dateFormatter.date(from:strDate) {
dateFormatter.dateFormat = "dd-MM-yyyy"
self.lblGlobalDateTime.text = “UTC Time = \(date)"
self.lblLocalDateTime.text = "Local Time = \(date.toLocalTime())"
print("datedate=", dateFormatter.string(from: date.toLocalTime()))
}
}

This is the extension used to get Local and UTC Time

extension Date {
func toUTCTime() - Date {
let timezone = TimeZone.current
let seconds = -TimeInterval(timezone.secondsFromGMT(for: self))
return Date(timeInterval: seconds, since: self)
}
// Convert UTC (or GMT) to local time
func toLocalTime() - Date {
let timezone = TimeZone.current
let seconds = TimeInterval(timezone.secondsFromGMT(for: self))
return Date(timeInterval: seconds, since: self)
}
}


🎉 Subscribe now for more videos on iOS development, and join our growing community of awesome enthusiasts! 🚀💙

🔔 Hit the notification bell so you never miss a moment – we've got more informative videos coming your way!

🤝 We value your feedback! Drop a comment below – share your thoughts, ideas, and what you want to see more of. This channel is for YOU! 🗣️💬

🚨 Don't forget to give this video a 👍 LIKE if you enjoyed it – it helps us a ton! Share it with your friends and family to spread the [positive vibes, knowledge, laughter]! 🌐👥

🌟 Thanks for being part of the family. Let's create something extraordinary together! 🌈✨


#Swift #Development #iOS #Xcode #iPhone tutorial for beginners #iOS Development #Swift Programming #App Development #User Interface #Auto Layout #Mobile App Design #UIKit #Mobile Development #Code Tutorial #SubscribeNow #JoinTheCommunity #AmandeepSinghChannel #DateFormatter