quanghuy9742
6/29/2018 - 3:58 AM

#timestamp #dateformatter #dateHumanRead

#timestamp #dateformatter #dateHumanRead

// Get timestamp
        let date = Date().timeIntervalSince1970
        let dateFormatter = DateFormatter()
        let timezone = TimeZone.current.localizedName(for: .shortStandard, locale: .current) ?? ""
        dateFormatter.timeZone = TimeZone(abbreviation: timezone)
        dateFormatter.locale = NSLocale.current
        dateFormatter.dateFormat = "yyyy-MM-dd HH:mm"
        let strDate = dateFormatter.string(for: Date(timeIntervalSince1970: date))
        
        // prepare advertisement data
        let data: Data = strDate!.data(using: String.Encoding.utf8)!