En_US 或 en-US,您应该使用哪一个?

假设您想在数据库中存储用户首选项的区域设置,您将使用哪个值?

不管是在美国还是在美国

它们是两个标准,但是您更愿意使用哪一个标准作为您自己应用程序的一部分?

更新 : 似乎很多网站使用破折号而不是下划线,例如。

Http://zh.wikipedia.org/zh-tw Http://www.google.com.hk/search?hl=zh-tw

116903 次浏览

en_US. This is a very useful read.

I don't think en-US is a standard at all for Java. (If you see it somewhere could you add a link).

So just use en_US.

If you're working with Java, you might as well use the Java locale format (en_US).

The BCP 47 documents actually do specify the en-US format, and it's just as common if not more common than Java-style locale names. But in practice you'll see the form with the underbar quite a bit. For example, both Java and most POSIX-type platforms use the underbar for their language/region separator.

So you can't go far wrong with either choice. But given that you're writing in Java and probably targeting a Unix platform, en_US is probably the way to go.

I'm pretty sure "-" is the standard. If you see "_" somewhere it's probably something some people came up with to make it a valid identifier.

Personally I'd go with "-", just to be correct.

http://en.wikipedia.org/wiki/IETF_language_tag

https://datatracker.ietf.org/doc/html/rfc5646

In Java 7, there is a new method Locale.forLanguageTag(String), which assumes the hyphen as a separator. I'd consider that as normative.

Check the documentation of Locale for more information.