简体   繁体   English

iPhone iOS 是否支持 UNIX C 语言环境?

[英]Does the iPhone iOS support UNIX C locales?

All I really want to do is format a date using strftime("%x") in the right order.我真正想要做的是以正确的顺序使用 strftime("%x") 格式化日期。 On most platforms a call to setlocale("") is enough.在大多数平台上,调用 setlocale("") 就足够了。 On iPhone iOS CI keep getting !@#$ US dates.在 iPhone iOS CI 上不断收到 !@#$ 美国日期。

So, does iPhone iOS C not support locales?那么,iPhone iOS C 不支持语言环境吗?

See similar question: Does the Android NDK support locales?看到类似的问题: Android NDK 支持语言环境吗?

No. setlocale() and strftime() does not work in IPhone iOS C, just NULL.否。 setlocale()strftime()在 iPhone iOS C 中不起作用,只是 NULL。

And the ANSI C localeconv() does not work in IPhone iOS C: ANSI C localeconv()在 iPhone iOS C 中不起作用:

struct lconv *localeconv(void);

Also the standard Unix way of getting user name, does not work in Android.获取用户名的标准 Unix 方式也不适用于 Android。

char *p = getenv("USER");

So you need to use the Swift side to get the locale information.所以需要使用 Swift 端来获取 locale 信息。

let RFC3339DateFormatter = DateFormatter()
RFC3339DateFormatter.timeZone = TimeZone(secondsFromGMT: 0)
RFC3339DateFormatter.dateFormat = "yyyy-MM-dd"
let LocaleDateFormatter = DateFormatter()
LocaleDateFormatter.locale = Locale(identifier: Locale.preferredLanguages[0]) //NSLocale.current.identifier)
LocaleDateFormatter.dateStyle = .short
let DateString = LocaleDateFormatter.string(from: RFC3339DateFormatter.date(from: "3333-11-22")!)
let LocaleCountry = NSLocale.current.regionCode
let LocaleLanguage = Locale.preferredLanguages[0]
let LocaleCurrency = NSLocale.current.currencyCode
let LocaleShortDateTimePattern = DateString
let LocaleDecimalSeparator = NSLocale.current.decimalSeparator
let LocaleThousandSeparator = NSLocale.current.groupingSeparator
let LocaleThousandGrouping =  "3;0",/* ThousandGrouping locale looks not be implemented by Apple*/
let LocaleNegativePrefix = NumberFormatter().negativePrefix
let LocaleNegativeSuffix = NumberFormatter().negativeSuffix
let Operator = NSUserName()

And then to be used in the C-code, call a C-function with the Swift locale data as parameters and store them there.然后要在 C 代码中使用,以 Swift 语言环境数据作为参数调用 C 函数并将它们存储在那里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM