How can I parse / create a date time stamp formatted with fractional seconds UTC timezone (ISO 8601, RFC 3339) in Swift?

后端 未结 12 1744
北恋
北恋 2020-11-21 22:43

How to generate a date time stamp, using the format standards for ISO 8601 and RFC 3339?

The goal is a string that looks like this:

\"2015-01-01T00:0         


        
12条回答
  •  旧时难觅i
    2020-11-21 23:33

    In my case I have to convert the DynamoDB - lastUpdated column (Unix Timestamp) to Normal Time.

    The initial value of lastUpdated was : 1460650607601 - converted down to 2016-04-14 16:16:47 +0000 via :

       if let lastUpdated : String = userObject.lastUpdated {
    
                    let epocTime = NSTimeInterval(lastUpdated)! / 1000 // convert it from milliseconds dividing it by 1000
    
                    let unixTimestamp = NSDate(timeIntervalSince1970: epocTime) //convert unix timestamp to Date
                    let dateFormatter = NSDateFormatter()
                    dateFormatter.timeZone = NSTimeZone()
                    dateFormatter.locale = NSLocale.currentLocale() // NSLocale(localeIdentifier: "en_US_POSIX")
                    dateFormatter.dateFormat =  "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
                    dateFormatter.dateFromString(String(unixTimestamp))
    
                    let updatedTimeStamp = unixTimestamp
                    print(updatedTimeStamp)
    
                }
    

提交回复
热议问题