NSDateFormatter, am I doing something wrong or is this a bug?

后端 未结 8 989
-上瘾入骨i
-上瘾入骨i 2020-11-30 06:18

I\'m trying to print out the date in a certain format:

NSDate *today = [[NSDate alloc] init];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]         


        
8条回答
  •  执念已碎
    2020-11-30 07:18

    I think this is the solution .

    NSDateFormatter *df =[[NSDateFormatter alloc] init];
            [df setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
            NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
    
    [df setLocale: usLocale];
    
    [usLocale release];
    
     NSDate *documento_en_Linea =[[[NSDate alloc] init]autorelease];
    
    documento_en_Linea=[df dateFromString:@"2010-07-16 21:40:33"];
    
    [df release];
    
            NSLog(@"fdocumentoenLineaUTC:%@!",documento_en_Linea);
    
    
    //ouput  
         fdocumentoenLineaUTC:2010-07-16 09:40:33 p.m. -0500!
    

提交回复
热议问题