iPhone 使用用户区域设置但以其他语言显示日期

发布于 2024-10-03 17:11:07 字数 108 浏览 1 评论 0原文

是否有任何解决方案可以使用用户的区域设置向用户显示日期,但单词采用不同的语言?

我想要的是向已设置en_US德语日期的用户显示(例如月份名称、工作日)。

Is there any solution to display to the user a date using his locale settings but the words to be in a different language?

What I want is to display to a user that has set up en_US a date in german language (month names, weekdays for example).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ぶ宁プ宁ぶ 2024-10-10 17:11:07

好问题。如果您首先使用用户的区域设置(默认)创建一个NSDateFormatter,设置其样式,然后存储当前的日期格式,这是可能的。之后,将区域设置设置为您想要显示的语言并重置日期格式:

NSDateFormatter *df = [[[NSDateFormatter alloc] init] autorelease];
[df setDateStyle:NSDateFormatterFullStyle];
NSString *usersDateFormat = [df dateFormat];
[df setLocale:[[[NSLocale alloc] initWithLocaleIdentifier(@"de_DE")] autorelease]];
[df setDateFormat:usersDateFormat];
NSString *dateString = [df stringFromDate:[NSDate date]];

Good question. It is possible if you first create an NSDateFormatter with the user's locale (default), set its style, then store the current date format. After that, set the locale to the language you want to display and reset the date format:

NSDateFormatter *df = [[[NSDateFormatter alloc] init] autorelease];
[df setDateStyle:NSDateFormatterFullStyle];
NSString *usersDateFormat = [df dateFormat];
[df setLocale:[[[NSLocale alloc] initWithLocaleIdentifier(@"de_DE")] autorelease]];
[df setDateFormat:usersDateFormat];
NSString *dateString = [df stringFromDate:[NSDate date]];
动次打次papapa 2024-10-10 17:11:07

NSDateFormatter 的 iOS 类参考有这样的示例代码:

http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSDateFormatter_Class/Reference/Reference.html

它位于概述部分。

基本上,您手动设置区域设置,格式化程序使用该区域设置格式化给定的日期。

The iOS Class Reference for NSDateFormatter has sample code for this:

http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSDateFormatter_Class/Reference/Reference.html

It is in the Overview section.

Basically, you manually set the locale, and the formatter formats the given date with that locale.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文