gpt4 book ai didi

c# - 如何以 Web.Config 中的本地化格式显示 DateTime 的字符串

转载 作者:太空宇宙 更新时间:2023-11-03 20:31:50 25 4
gpt4 key购买 nike

我使用 Asp.net 4 和 C#。

我的数据库中有一个表,其中的日期时间列格式如下:2011-08-11 11:32:50.43

我需要根据 Web.Config 以正确的格式显示带有 DateTime 的字符串就我而言:

<globalization culture="auto:de" uiCulture="de"/>

所以我的问题是:如何根据 globalization culture 设置表示 DateTime 的字符串?

最佳答案

我想这就是你需要的: DateTime.ToString Method (IFormatProvider)

对于您的情况,它必须如下所示:

        CultureInfo culture = new CultureInfo("de-DE");
DateTime curretnDate = DateTime.Now;

Console.WriteLine("Date : {0}",
curretnDate.ToString(culture));

关于c# - 如何以 Web.Config 中的本地化格式显示 DateTime 的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7157237/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com