NSDate 希伯来语日期标签 [英] NSDate hebrew date label

查看:94
本文介绍了NSDate 希伯来语日期标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用今天的日期制作标签,但我需要今天的希伯来语日期.

I make label with the date for today but I need hebrew date for today.

这是我的代码

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

我没有用今天的日期制作日历这个标签.

I not build calendar this label with date for today.

谢谢!

推荐答案

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

Assuming the user's current locale is not set for Hebrew, then you need to ensure the date formatter's locale is set for Hebrew,

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

该代码仍将使用用户当前语言环境(例如公历)的日历.如果您还需要希伯来日历,那么您需要这个:

That code will still use the calendar for the user's current locale (such a Gregorian). If you also need the Hebrew calendar, then you need this:

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

这篇关于NSDate 希伯来语日期标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆