Modify application wide, the display of DateTime(修改应用范围,日期时间的显示)
问题描述
对于我们开发的应用程序,我们在应用程序的任何地方都使用 "G" 格式.
For an application we develop, we use the "G" format everywhere in our application.
我们想稍微改变一下这种格式:
We want to change a little bit this format:
我们需要在第二个之后显示第一个数字.
We need to display the first digit after the second.
例如:
29.07.2014 08:54:36.1
29.07.2014 08:54:36.1
我们希望能够在 CurrentCulture 中对此进行更改.
We would like to be able to change this in the CurrentCulture.
这是我们在当前文化中唯一想要改变的,所以如果以前,我们有以下格式:
It's the only thing we want to change in the current culture, so if before, we were having the following format:
2014 年 7 月 29 日上午 8 点 54 分 36 秒
2014/07/29 08:54:36 AM
然后我们想要拥有
2014/07/29 08:54:36.1 上午
2014/07/29 08:54:36.1 AM
如果在我有之前
29.07.2014 08:54:36
29.07.2014 08:54:36
然后我们想要拥有
29.07.2014 08:54:36.1
29.07.2014 08:54:36.1
如果我们收到的 DateTime 没有要在此处显示的数字(=0 十分之一秒),则不显示此数字是一件好事.
A nice to have would be, that if the DateTime we receive, doesn't have a digit to be displayed here( =0 tenth of seconds), to don't have this displayed.
推荐答案
您可以设置CurrentCulture 为当前线程指定一个偏离的LongTimePattern:
CultureInfo culture = Thread.CurrentThread.CurrentCulture.Clone();
change the culture.DateTimeFormat.LongTimePattern = "your pattern";
Thread.CurrentThread.CurrentCulture = culture;
这篇关于修改应用范围,日期时间的显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:修改应用范围,日期时间的显示
基础教程推荐
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- WPF 模态进度窗口 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
