title: Convert 12Hr UTC date to 24Hr Local TimeZone format in Swift
body: <p>As per <a href="https://www.worldtimebuddy.com" rel="nofollow noreferrer">UTC to IST conversion tool</a> if UTC 12Hr date string is <code>= "2018-12-31 07:35 PM"</code> then it needs to be converted as <code>"2019-01-01 01:05"</code> (24Hr format in IST) <em>[note : here 12Hr IST converted date is "2019-01-01 01:05 AM"]</em></p>
  
  <p>So how do to convert this 12Hr UTC date into 24Hr IST dateFormat?</p>
  
  <p>current code is  :</p>
  
  <pre><code>static func convertUTCdateToLocalTimezoneDate(dateString: String, fromDateFormat: String, toDateFormat: String) -&gt; String {
          if dateString.count &gt; 0 {
              let dateFormatter = DateFormatter()
              let is24Hr: Bool = AppUtility.isSystemTimeFormatIs24Hr(dateString: AppUtility.getIphoneCurrnetTime())
              let fromDateFormatLocal = is24Hr == true ? kDateIn24Format : kDateIn12Format
              dateFormatter.dateFormat = fromDateFormatLocal
              dateFormatter.timeZone = TimeZone(abbreviation: "UTC")
              let date = dateFormatter.date(from: dateString)
              var timeStamp = ""
              dateFormatter.dateFormat = toDateFormat
              dateFormatter.timeZone = NSTimeZone.local
              timeStamp = dateFormatter.string(from: date!)
              return timeStamp
          }
          return ""
      }
  
  static func isSystemTimeFormatIs24Hr(dateString: String) -&gt; Bool {
      let formatter = DateFormatter()
      formatter.locale = NSLocale.current
      formatter.dateStyle = .none
      formatter.timeStyle = .short
      let amRange: NSRange? = (dateString as NSString).range(of: formatter.amSymbol)
      let pmRange: NSRange? = (dateString as NSString).range(of: formatter.pmSymbol)
      let is24h: Bool = amRange?.location == NSNotFound &amp;&amp; pmRange?.location == NSNotFound
      return is24h
  }
  </code></pre>