2012-10-28 38 views
1

我为今天的日期制作标签,但我需要今天的希伯来语日期。NSDate希伯来语日期标签

这是我的代码

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

我不能建立日历这个标签包含日期为今天。

谢谢!

回答

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]; 
+1

תודהרבה:)!!!! – Luda

+0

我无法阅读希伯来文。请英语。 :) – rmaddy

+0

只是说谢谢:)你怎么会遇到这个问题,如果你不说希伯来语? – Luda