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

Meteor app: Difference Between Uploading Images from Iphone than Computer?
NodeJS(SocketIO) authentication token
When writing to text file (appending) the last value I write replaces all previous values
How to use WebP image in UIImageView Swift
How to get rid of the glitch that occurs right after pressing the back button?
Distance between two UIButtons according to screen size? [closed]
Creating ssl public and private key pair in ios app
How to Renaming a Project or App in XCode? [duplicate]
ios - how to have Multiple lines of NSAttributedString
Granting permission for the calendar without showing ios builtIn alertView
iOS JSON Parsing, Format Issues
UIButton in scrollView position unexpected
cross building binutils 2.25.1 for iOS8.4 (arm64-apple-darwin14.0.0)
SWIFT: Modal Segue From TableViewCell (Prototype Cell) Is Not Working
NSDictionary is nil when I decode with NSKeyedUnarchiver even when passing valid data object
Why are my Parse API requests increasing rapidly each day?

Categories

HOME
validation
web-applications
whatsapp
magento
office-js
openshift-origin
haskell-stack
styling
swashbuckle
openvpn
mvvm-light
build.gradle
asp.net-mvc-3
akka.net
apache-spark-sql
superfish
asciidoc
sparkpost
axios
cloudrail
apache-kafka-streams
gitlab-ci-runner
gyroscope
swig
pydev
sfsafariviewcontroller
ghost-blog
pwm
polynomials
jcrop
easendmail
liferay-aui
naturallyspeaking
epicorerp
php-carbon
listbox
expression-trees
file-manager
charts.js
django-users
machine-language
doctrine-odm
deep-copy
bcel
bits
qweb
dsx
ibm-wcm
amazon-vpc
internet-explorer-10
subscription
mamp-pro
stateful
nexus-5
ulimit
xargs
keyboard-maestro
rating-system
sql-mode
domdocument
jasmine2.0
autogen
vs-2015-preview
atmosphere.js
tachyon
mysql-notifier
surroundscm
sqlfiddle
enhanced-ecommerce
sliding
gcloud-java
multiple-files
jni4net
genetic
sample-data
ironmq
spl
ubiquity
kindlegen
selectsinglenode
telescope
pencilblue
smarty2
servlet-listeners
cvs2git
sqlhelper
django-postgresql
linguistics
django-supervisor
delphi-2009
sqlprofiler
memoization
rcu
gdb-python
hudson-plugins
vote
mixing
mysql-backup
onmouseout
rgba
hpple
quilt
molehill
semantic-zoom
azure-role-environment
duplicate-data
jtemplates
coolstorage
apache-config
variable-names
usenet
graceful-degradation

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