ios - NSDate希伯来语日期标签

标签 ios nsdate hebrew

我用今天的日期做标签,但是我需要今天的希伯来语日期。

这是我的代码

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

我没有用今天的日期来建立这个标签的日历。

谢谢!

最佳答案

假设未为希伯来语设置用户的当前语言环境,那么您需要确保为希伯来语设置日期格式程序的语言环境,

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

该代码仍将使用日历作为用户当前的语言环境(例如Gregorian)。如果您还需要希伯来语日历,则需要这样做:
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];

关于ios - NSDate希伯来语日期标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13109624/

相关文章:

ios - 在iPhone和移动设备上显示图表

ios - 匹配 NSDictionary 键值对

ios - 我怎样才能得到昨天的 NSDate

r - 在字符串中使用希伯来字符

php - 通过php将希伯来语插入mySql数据库

ios - 单元格内的 Collection View 有时会混淆您的数据

ios - 在 SWIFT 的谓词中使用 "timeIntervalSinceNow"

mysql - iOS - 将从 mySQL 服务器接收到的日期转换为用户本地时间

ios - 从 NSDate 中减去分钟数

mysql - 问题从批处理文件将希伯来语插入 mysql 表中