Monday, 19 June 2017

Convert Date to time ago in swift 3 - Tutorial


Convert Date to time ago  in swift3 - Tutorial

Introduction to tutorial on Convert Date to time ago in swift 3

I in this tutorial I am going to share a short written extension of Date class that will convert given date and time with respect to current date time into seconds ago, minutes ago, days ago, and so on. If we are creating a feed based app or app showing listing of posts, then we have requirement to show time elapsed from the time of feed/post posting to the current time of the device.

Extension for Date that convert given date to time ago

Below is the code for the extension



Step 2: In  ViewController.swift file, viewDidLoad function, we will use it as shown below. We are passing -180 to create date 3 minutes behind current date.




No comments:
Write comments