本文介绍了NSDateformatter setDateFormat根据currentLocale的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会疯了,可能是一个愚蠢的问题。

I'm going mad with, probably, a stupid problem.

我有3个字符串:年,月和日。我需要一个基于currentLocale的正确格式的日期,所以ie如果currentLocale localeIdentifier是en_US我的dateFormat应该是:
MMM / dd / yyyy

I have 3 strings: year, month and day. I need to have a date in the right format based on currentLocale, so i.e. if currentLocale localeIdentifier is en_US my dateFormat should be:MMM/dd/yyyy

如果是fr_FR,dateFormat应为dd / MMM / yyyy

if it's fr_FR the dateFormat should be dd/MMM/yyyy

我不认为这样做的唯一方法是获取currentLocale localeIdentifier并开始一堆if

I don't think the only way to do this is to get currentLocale localeIdentifier and start with a bunch of if then.

提前感谢。

最大

推荐答案

看看NSDateComponents创建一个NSDate,然后使用NSDateFormatter来格式化它。 NSDateFormatter使用当前语言环境根据格式样式(例如

NSDateFormatterMediumStyle )格式化日期。

Look at NSDateComponents to create an NSDate, then use NSDateFormatter to format it. NSDateFormatter uses the current locale to format dates, based on the format style (e.g.
NSDateFormatterMediumStyle).

这篇关于NSDateformatter setDateFormat根据currentLocale的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-24 05:01