1 Reply
      Latest reply on Jul 14, 2018 2:49 AM by OOPer
      mksmurali Level 1 Level 1 (0 points)

        Hi

        How to convert the string "14 Jul 2018 10:45" to date?

        • Re: how to convert the string "14 Jul 2018 10:45" to date?
          OOPer Level 7 Level 7 (4,495 points)

          You can use `DateFormatter` to parse String representation of date.

           

          let dateStr = "14 Jul 2018 10:45"
          
          let formatter = DateFormatter()
          formatter.locale = Locale(identifier: "en_US_POSIX") //<~better specify "en_US_POSIX" when you set `dateFormat`
          formatter.timeZone = TimeZone(abbreviation: "PST") //<-You need to decide which timezone your app will choose
          formatter.dateFormat = "dd MMM yyyy HH:mm"
          let date = formatter.date(from: dateStr)
          print(date) //->Optional(2018-07-14 17:45:00 +0000)
          

           

          You many need to decide whether to use the TimeZone where user has chosen or to use some specific TimeZone as in the above example.