wrong time using NSDateFormatter
I know there is several question about this. But i tried all the recommendation and still the time doesn't match the time atonmy real device.
let dater = NSDate() let dayTimePeriodFormatter = NSDateFormatter() dayTimePeriodFormatter.locale = NSLocale.currentLocale() dayTimePeriodFormatter.timeZone = NSTimeZone(name: "UTC") dayTimePeriodFormatter.dateFormat = "H:s" var dateString = dayTimePeriodFormatter.stringFromDate(dater)
Device(real) time : 22:11 . dateString output : 00:36
Any suggestions? Thanks!
As Nick points out, you're using UTC as your time zone, and you can get to the local time zone with NSTimeZone.systemTimeZone()
It's also likely that you don't really intend to use just the hours (H) and seconds (s) You probably also want the minutes (m). Try using a dateFormat of "H:m:s"
Better yet, use "H:mm:ss" which will force the minutes and seconds to be two digits, as opposed to just one, so you don't wind up with "10:4:3"
Have you tried dayTimePeriodFormatter.dateFormat = "HH:mm"?
Apple uses fixed Internet. Check out here to see some examples. This may be helpful