在.NET中获取当前的文化日名称

编程入门 行业动态 更新时间:2024-10-26 12:32:11
本文介绍了在.NET中获取当前的文化日名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

可以从 DateTimeFormatInfo 获取 CurrentCulture 的工作日,但返回星期一作为第一天,而不是星期日。而且,如果目前的文化不是英文(即ISO代码不是en),那么请默认为。

Is it possible to get the CurrentCulture's weekdays from DateTimeFormatInfo, but returning Monday as first day of the week instead of Sunday. And, if the current culture isn't English (i.e. the ISO code isn't "en") then leave it as default.

默认情况下 CultureInfo.CurrentCulture.DateTimeFormat.DayNames 返回:

[0]: "Sunday" [1]: "Monday" [2]: "Tuesday" [3]: "Wednesday" [4]: "Thursday" [5]: "Friday" [6]: "Saturday"

但是我需要:

But I need:

[0]: "Monday" [1]: "Tuesday" [2]: "Wednesday" [3]: "Thursday" [4]: "Friday" [5]: "Saturday" [6]: "Sunday"

推荐答案

您可以使用定制文化,以创建一个基于现有文化的新文化。说实话,我会说这可能有点沉重。 最简单的解决方案可能只是这样:

You can use custom cultures to create a new culture based off an existing one. To be honest, though, I'd say that's probably a bit heavy-handed. The "simplest" solution may just be something like:

public string[] GetDayNames() { if (CultureInfo.CurrentCulture.Name.StartsWith("en-")) { return new [] { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" }; } else { return CultureInfo.CurrentCulture.DateTimeFormat.DayNames; } }

更多推荐

在.NET中获取当前的文化日名称

本文发布于:2023-11-10 03:01:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1574164.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:名称   文化   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!