代码之家  ›  专栏  ›  技术社区  ›  Aran Mulholland JohnnyAce

NSString long date格式到NSDate

  •  0
  • Aran Mulholland JohnnyAce  · 技术社区  · 14 年前

    我有一根

    如何将其转换为NSDate对象?

    2 回复  |  直到 14 年前
        1
  •  1
  •   Simon    14 年前

    NSString *input = @"11:00AM, Saturday August 21, 2010";
    NSDateFormatter *df = [[[NSDateFormatter alloc] init] autorelease];
    [df setDateFormat:@"hh:mma, EEEE MMMM d, yyyy"];
    NSDateFormatter *df2 = [[[NSDateFormatter alloc] init] autorelease];
    [df2 setDateFormat:@"MMMM yyyy"];
    NSDate *date = [df2 stringFromDate:[df dateFromString:input]];


    并根据需要设置日期对象的格式。
    http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns

        2
  •  1
  •   Eiko    14 年前

    NSDateFormatter 对于此格式。 -(NSDate *)dateFromString:(NSString *)string 是你想用的方法。