why is some strange character in NSDate string
I am using below code to get date time. I will post them to server let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" let strDate = dateFormatter.stringFromDate(NSDate()) In server, I found there several log has strange data. it is encoded as "date": "\u0662\u0660\u0661\u0666-\u0660\u0664-\u0661\u0660 \u0661\u0668:\u0665\u0669:\u0664\u0663" I found them show as ٢٠١٦-٠٤-١٠ ١٨:٥٩:٤٣ in UTF16, what is the problem, it seems date format is correct, but why year-month-day hour:minitue:seconds become invalid. Thanks~
Just set the locale on the formatter: let dateFormatter = NSDateFormatter() dateFormatter.locale = NSLocale(localeIdentifier: "en_US_POSIX") en_US_POSIX is a standardized locale that will never change (even if the US were to change how it encodes things). As A-Live notes, these are valid digits and valid dates. They're just not Western Arabic digits (0123456789). They're Eastern Arabic digits (٠١٢٣٤٥٦٧٨٩). stringFromDate() uses the locale from the formatter. If you don't set one, it uses the system locale. If you want a particular one, set it. See QA1480 for full details.
These are totally valid year, month, day, etc: based on your code we can see that you've decided to accept the values of any locale, including non-arabic digits.
get remote push notification message in background in iOS
Why can't I bold just part of a string in Swift with NSMutableString?
Swift - WebView doesn't detect swipes when loading
Interstitial DFP ad doesn't fill the screen
Q:UITableView scrollview delegate method did not pass the special code
ios Xcode storyboard compact not working
iOS - Where is object stored in application NSUserDefault? [duplicate]
UIImage to NSData fatal error: unexpectedly found nil while unwrapping an Optional value
How to load images for UITableView or UICollectionView from cache everytime
iOS - UITableview cells with shared surface
Xcode fix memory problems
UIWebview remove padding / margin
How do I not get optional in the output?
Material Select blinking on iOS
How to get the Core data Primary key value in ios Swift? [duplicate]
How to remove only minutes from UIDatePickerMode.DateAndTime