Nsdateformatter returns me day in language of the phone selected. Can it return me only English all the time?

前端 未结 3 2003
遥遥无期
遥遥无期 2021-02-04 01:45

I am using dateformatter to get days and time in the my application. But I am facing an issue when I change the language of the phone dateformatter returns me day and time of th

3条回答
  •  长情又很酷
    2021-02-04 02:08

    Try with this code:

    NSDate *date=[NSDate date];
    NSDateFormatter *objTimeFotmatter=[[NSDateFormatter alloc]init];
    [objTimeFotmatter setDateFormat:@"HH:mm"];
    [objTimeFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]
    autorelease]];
    NSDateFormatter *objDayFotmatter=[[NSDateFormatter alloc]init];
    [objDayFotmatter setDateFormat:@"EEEE"];
    [objDayFotmatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]
    autorelease]];
    NSString *objTime=[objTimeFotmatter stringFromDate:date];
    NSString *objDay=[objDayFotmatter stringFromDate:date];
    [objDayFotmatter release];
    [objTimeFormatter release];
    
    NSLog(@"objTime=%@",objTime);
    NSLog(@"objDay=%@",objDay);
    

提交回复
热议问题