Convert timestamp to Date or Time or DateTime Both

PHOTO EMBED

Sat Jan 08 2022 09:39:33 GMT+0000 (Coordinated Universal Time)

Saved by @hasnat #ios #swift #date #time #datetime

    func getDateTime(_ timeStamp : String,_ format: String) -> String {
        var t1 = Int(timeStamp) ?? 1
         t1 = t1/1000
        let date = NSDate(timeIntervalSince1970: TimeInterval(t1))
        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = format
        let dateString = dateFormatter.string(from: date as Date)
        print("Date = \(dateString)")
        return dateString
    }
content_copyCOPY

if you want to convert timeStamp to DateTime you have to pass timeStamp and DateTime format that you want in return. this func will return you dateTime String.