ios - iphone Date from string -


i have 1 string

nsstring *timestr =@"04:57pm"; 

this date formatter

nsdateformatter *dateformat = [[nsdateformatter alloc] init]; [dateformat setdateformat:@"hh:mma"];     

converting nsstring nsdate

nsdate *date=[dateformat datefromstring:timestr]; nslog(@"date :::%@",date);  

the output in log

date :::1970-01-01 11:27:00 +0000. 

can know output date :::04:57pm.

you need use same nsdateformatter , stringfromdate method same string. date different because haven't set locale on nsdateformatter.


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -