1

今日の日付でラベルを作成しますが、今日のヘブライ語の日付が必要です。

これは私のコード

NSDate *today = [NSDate date];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateStyle:NSDateFormatterShortStyle];
NSString *dateString = [dateFormat stringFromDate:today];
[_label setText:dateString];

私は今日の日付でこのラベルのカレンダーを作成しません。

ありがとう!

4

1 に答える 1

4

ユーザーの現在のロケールがヘブライ語に設定されていないと仮定すると、日付フォーマッターのロケールがヘブライ語に設定されていることを確認する必要があります。

NSLocale *hebrew = [[NSLocale alloc] initWithLocaleIdentifier:@"he_IL"]; // Hebrew, Israel
NSDate *today = [NSDate date];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
dateFormat.locale = hebrew;
[dateFormat setDateStyle:NSDateFormatterShortStyle];
NSString *dateString = [dateFormat stringFromDate:today];
[_label setText:dateString];

そのコードは、引き続きユーザーの現在のロケール (グレゴリオ暦など) のカレンダーを使用します。ヘブライ暦も必要な場合は、次のものが必要です。

NSLocale *hebrew = [[NSLocale alloc] initWithLocaleIdentifier:@"he_IL"]; // Hebrew, Israel
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSHebrewCalendar];
NSDate *today = [NSDate date];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
dateFormat.locale = hebrew;
dataFormat.calendar = calendar;
[dateFormat setDateStyle:NSDateFormatterShortStyle];
NSString *dateString = [dateFormat stringFromDate:today];
[_label setText:dateString];
于 2012-10-28T16:09:03.423 に答える