ios - Get the user's date format? (DMY, MDY, YMD) -
i'm creating form user can enter birthday 3 uitextfields: 1 month, 1 day , 1 year. i'd arrange them based on user's date format.
i.e.: [ month ] [ day ] [ year ] american users, [ day ] [ month ] [ year ] european users, etc.
map of date format country: http://en.wikipedia.org/wiki/date_format_by_country#map
what's easiest way format?
right i'm setting date october, 20 2000 , parsing string.
nscalendar *calendar = [nscalendar currentcalendar]; nsdatecomponents *components = [[nsdatecomponents alloc] init]; [components setday:20]; [components setmonth:10]; [components setyear:2000]; nsdate *date = [calendar datefromcomponents:components]; nslog(@"%@", [nsdateformatter localizedstringfromdate:date datestyle:nsdateformattershortstyle timestyle:nsdateformatternostyle]); but don't think it's right thing since got many different formats:
us: 10/20/00
fr: 20/10/00
japan: 2000/10/20
sweden: 2000-10-20
you can make use of nsdateformatter dateformatfromtemplate:options:locale:.
nsstring *base = @"mm/dd/yyyy"; nslocale *locale = [nslocale currentlocale]; nsstring *format = [nsdateformatter dateformatfromtemplate:base options:0 locale:locale]; the value of format adjusted right format based on locale. trick scan format see order find m, d, , y.
Comments
Post a Comment