修改应用范围,日期时间的显示 [英] Modify application wide, the display of DateTime

查看:22
本文介绍了修改应用范围,日期时间的显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我们开发的应用程序,我们在应用程序的任何地方都使用 "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;

这篇关于修改应用范围,日期时间的显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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