ios - Date formats from device based on locale -
as per knowledge date format vary based on locale, there way read date-format device's local settings current date?
- whether date format "dd/mm/yyyy" or "mm/dd/yyyy".
- time format "h:mm a" or else.
- the am/pm text "am" or "pm".
i can't afford third party libraries, please tell me whether can done using apple classes.
edited:
i don't want set formats, want retrieve device based on locale.
say, here in country date format dd/mm/yyyy in part of word mm/dd/yyyy want format.
any answer appreciated.
i thought, simple fix. on seeing cool answers question, went curious it. here solution.
you can use nsdateformatter this, set style required formats
nsdateformattershortstyle nsdateformattermediumstyle nsdateformatterlongstyle to know more please take @ documentation
below snippet you.
nsdateformatter *dateformatter = [[[nsdateformatter alloc] init] autorelease]; [dateformatter setdatestyle:nsdateformattershortstyle]; nsstring *dateformat = [dateformatter dateformat]; //m/d/yy nsstring *amtext = [dateformatter amsymbol]; //am nsstring *pmtext = [dateformatter pmsymbol]; //pm dateformatter = [[[nsdateformatter alloc] init] autorelease]; [dateformatter settimestyle:nsdateformattershortstyle]; nsstring *timeformat = [dateformatter dateformat]; //h:mm it use user's locale formats. hope solves problem.
Comments
Post a Comment