Swift implements simple timestamp conversion
The publication timestamp is compared to the current time: a few seconds ago ... Days ago. Swift Syntax Time Stamp Transformation code block Createdtime: Publish time stamp
Swift Timestamp Conversion method func timestamp ()-> string {var timestamp = string () var now = time_t () time (&now)
Createdtime publish timestamp var distance = Int (Difftime (now, createdtime)) if distance < 0 {Distance = 0 } if distance < timestamp = nsstring (format: "%d%@", distance, (distance = 1)? "Seconds ago": "Seconds Ago") as String} else if distance < distance = Distance/60 timestamp = Stri NG (format: "%d%@", distance, (distance = 1)? "Minutes ago": "Minutes Ago")} else if distance < * distance = distance/60/60 timestamp = St Ring (format: "%d%@", distance, (distance = 1)? "Hours ago": "Hours Ago")} else if distance < * * 7 {distance = distance/60/60/24 times Tamp = String (format: "%d%@", distance, (distance = = 1)?
"Days before": "Days Before")} else if distance < * 7 * 4 {distance = DISTANCE/60/60/24/7; timestamp = String (format: "%d%@", distance, (distance = 1)? "Weeks ago": "Weeks Ago")} else {Let dateformatter = NSDateFormatter () If Dateformatter = "" {L ET dateformatter = NSDateFormatter () Dateformatter.timestyle =. Shortstyle Dateformatter.datestyle =. Shortstyle} Let date = NSDate (timeintervalsince1970:createdtime) timestamp = Dateformatter.strin
Gfromdate (date)} return timestamp}
you are welcome to study and progress together ^. ^^. ^