NodaTime中时区的长形名称 [英] Long form name of timezone in NodaTime

查看:194
本文介绍了NodaTime中时区的长形名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



例如,如果我提供America / Los_Angeles,那么在NodaTime中,如何找到时区的长格式名称?我应该得到太平洋标准时间。

解决方案

您需要制作时区长形的信息名称不在Noda时间,但可以在 CLDR 中找到



我最近汇编了一个名为时区名称的库,嵌入了CLDR时区名称。您可以使用这些与Noda Time时区使用的IANA(TZDB)标识符。





只需传递时区和语言,它将提供相应的通用名称,标准名称和日光名称。您可以使用Noda Time来决定哪种表单适合显示。

  var names = TimeZoneNames.GetNamesForTimeZone(America / Los_Angeles ,en-US); 

Assert.Equal(太平洋时间,names.Generic);
Assert.Equal(太平洋标准时间,names.Standard);
Assert.Equal(太平洋夏令时,names.Daylight);

对于该语言,您可以传递两位数代码,如en ,或者您可以通过一个完全区域化的版本,如en-US。这符合 CultureInfo 名称,因此如果您愿意,可以通过 CultureInfo.CurrentUICulture.Name


In NodaTime, how do you find the long form name of a timezone given the tz timezone id?

For example, if I supply "America/Los_Angeles", I should get "Pacific Standard Time" back.

解决方案

The information you need to produce the "long form" of a time zone name isn't in Noda Time, but it can be found in the CLDR.

I've recently put together a library called simply "Time Zone Names", that embeds the CLDR time zone names. You can use these with the IANA (TZDB) identifiers that are used by Noda Time time zones.

Simply pass the time zone and language, and it will provide the appropriate generic name, standard name, and daylight name. You can use Noda Time to decide which form is appropriate to display.

var names = TimeZoneNames.GetNamesForTimeZone("America/Los_Angeles", "en-US");

Assert.Equal("Pacific Time", names.Generic);
Assert.Equal("Pacific Standard Time", names.Standard);
Assert.Equal("Pacific Daylight Time", names.Daylight);

For the language, you can pass either a two digit code like "en", or you can pass a fully regionalized version such as "en-US". This aligns with CultureInfo names, so you can pass CultureInfo.CurrentUICulture.Name if you like.

这篇关于NodaTime中时区的长形名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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