ios


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.

Related Links

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

Categories

HOME
regex
validation
wpf
sqlite
dynamics-crm-365
spring-roo
applet
azure-web-sites
isis
prebuild
wxpython
api.ai
xcode8
logback
box
jbpm
webdriver-io
range
pymc3
frequency
openui5
html5-video
watchservice
amadeus
cadvisor
symbolic-math
italic
pvs-studio
centos6
esri
parallax.js
operator-keyword
coqide
android-imageview
svn2git
udid
complex-networks
stackexchange.exceptional
sinon
drupal-webform
uitabbarcontroller
mamp-pro
qmake
quicksand
maven-jetty-plugin
php-deployer
oracle-aq
hostapd
pseudo-element
formstack
notimplementedexception
database-cleaner
attributerouting
abbyy
ietf-netconf
javascript-security
lcov
db2400
sizing
android-chips
xnamespace
sizeof
winobjc
uploadify
strace
administrator
tag-helpers
post-processor
openejb
rdotnet
realm-list
translate3d
sketching
spatial-index
sql-server-ce-3.5
easynetq
emberfire
java-client
adserver
puppet-enterprise
tab-delimited
office-2010
sendto
dojo.gridx
wmv
hebrew
azimuth
data-dictionary
inputview
colormatrix
libavcodec
bochs
external-dependencies
git-gui
java-ee-5
51degrees
ria
data-oriented-design
ladon
ssao
xmltextwriter
staging
jdic
sloc
dynamic-websites
68hc11
stsadm
shareware

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App