2017-12-26 16 views
1

내 응용 프로그램은 2 개 언어로되어 있으며 하나는 영어이고 다른 하나는 스페인어입니다. 이제 서버에서 타임 스탬프를 받으면 "MMM dd, yyyy"형식으로 날짜를 표시해야합니다. 이것은 "Dec 23, 2017"입니다.하지만 스페인어로 변환하면 스페인어로 월 이름을 표시해야합니다. 약식으로 12 개월 이름을 스페인어로 지정 하시거나 NSDateFormatter에이 유형의 옵션이 있습니까? 당신이스페인어와 같은 특정 언어의 Nsdateformatter

NSDateFormatter * 포맷터 = [[NSDateFormatter의 ALLOC] 초기화]의 위치를 ​​설정할 필요가 특정 언어에 대한

NSDate *date = [dateFormatter dateFromString:[[[webserviceDict valueForKey:@"CurrentWeekEarning"]objectAtIndex:i-1]valueForKey:@"date"]]; 
         [dateFormatter setDateFormat:@"MMM dd, yyyy"]; 
         strTitle = [NSString stringWithFormat:@"%@",[dateFormatter stringFromDate:date]]; 
+0

확인'dateFormatter.locale' https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPInternational/InternationalizingLocaleData/InternationalizingLocaleData .html – Hackerman

+0

날짜 형식 작성기를 작성하고 설정하는 방법을 보여주는 질문을 업데이트하십시오. – rmaddy

답변

1

그냥 (올바른 순서를 설정하는) 로케일을 설정하지 않고 템플릿에서 형식을 만듭니다

NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 
formatter.locale = [NSLocale localeWithLocaleIdentifier:@"es"]; 
[formatter setLocalizedDateFormatFromTemplate:@"yyyyMMMdd"]; 
NSString *localizedDate = [formatter stringFromDate:[NSDate date]]; 
NSLog(@"Localized date: %@", localizedDate); // 26 dic 2017 

수동 쉼표 또는 기타 구분 기호를 추가 할 필요가 있습니다. 그들은 또한 언어에 의존합니다.

미리 정의 된 형식을 사용하여 달성 할 수 같은 :

NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 
formatter.locale = [NSLocale localeWithLocaleIdentifier:@"es"]; 
formatter.timeStyle = NSDateFormatterNoStyle; 
formatter.dateStyle = NSDateFormatterMediumStyle; 
+0

감사 Sulthan 그것은 굉장해. :) – Chandni

-1

;

[포맷터 setDateStyle : 스타일];

[formatter setDateFormat : @ "MMM dd, yyyy"];

NSDate * temp = [formatter dateFromString : strDate];

[formatter setDateFormat : format];

[포맷터 setLocale : [NSLocale currentLocale]];

+2

형식을 설정하는 경우 스타일을 설정할 필요가 없습니다. 수동으로. 이상적으로는 특정 형식을 설정하지 말고 서식 파일을 사용하여 로캘 형식을 만듭니다. 그렇지 않으면 날짜가 올바르게 지역화되지 않습니다. – Sulthan