dateFromString永远返回nil的处理办法

    xiaoxiao2025-10-09  3

    NSDateFormatter *fmt = [[NSDateFormatter alloc] init]; fmt.dateFormat = @"EEE MMM dd HH:mm:ss Z yyyy"; NSDate *stutsCreatedDate = [fmt dateFromString:_created_at];

    以上是格式化时间格式为指定格式的代码,但是通过运行发现最后一句得到的nsdate永远都是nil ,查询无数文章最终解决。代码修改为

    NSDateFormatter *fmt = [[NSDateFormatter alloc] init]; fmt.dateFormat = @"EEE MMM dd HH:mm:ss Z yyyy"; [fmt setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]]; NSDate *stutsCreatedDate = [fmt dateFromString:_created_at];

    转载请注明原文地址: https://ju.6miu.com/read-1302981.html
    最新回复(0)