For iPhone OS 4.0 “dateFromString” method of NSDateFormatter returns nil

前端 未结 3 1222
予麋鹿
予麋鹿 2021-02-06 06:12

I am using following code & its working perfectly fine in iPhone OS 3.2

+(NSDate *)NSDateFromString:(NSString *)dateString
{

 NSDateFormatter *dateFormatter         


        
3条回答
  •  执念已碎
    2021-02-06 06:41

    [NSDateFormatter dateFormatFromTemplate:options:locale:] might work better

    NSString *format = [NSDateFormatter
                       dateFormatFromTemplate:@"Mdjm"
                                      options:0
                                       locale:[NSLocale currentLocale]];
    

    // "M/d h:mm a" // US English format returned for US locale

    [dateFormatter setDateFormat:format];
    NSDate *date = [dateFormatter dateFromString:dateString];
    

提交回复
热议问题