1 . From millisecond to date time format and show on a label

[java]
let date = Date(timeIntervalSince1970: (yourDateValue / 1000.0))

let dateFormatter = DateFormatter()
dateFormatter.timeZone = TimeZone(abbreviation: "GMT") //Set timezone that you want
dateFormatter.locale = NSLocale.current
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm" //Specify your format that you want
let strDate = dateFormatter.string(from: date)

publishedDate.text = strDate

[/java]

2 . From unix to date time format and show on a label

[java]
let date = Date(timeIntervalSince1970: (yourDateValue))

let dateFormatter = DateFormatter()
dateFormatter.timeZone = TimeZone(abbreviation: "GMT") //Set timezone that you want
dateFormatter.locale = NSLocale.current
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm" //Specify your format that you want
let strDate = dateFormatter.string(from: date)

publishedDate.text = strDate

[/java]

Leave a Reply

Your email address will not be published. Required fields are marked *