如何在vb中的标签中获取我的系统短日期格式。净 [英] How can I get my system short date format in a label in vb. Net

查看:148
本文介绍了如何在vb中的标签中获取我的系统短日期格式。净的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好先生

如何在vb的标签中获取我的系统短日期格式。净。我试试这段代码:



 Label1.Text = System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern()



但显示错误的数据。所有时间都显示M / d / yyyy格式。

我手动更改它(到dd / MM / yyyy)并且编码结果相同(M / d / yyyy)请帮帮我.....



我尝试过的事情:



 Label1.Text = System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern()





For Change格式:

 Microsoft.Win32.Registry.SetValue(HKEY_CURRENT_USER \Control Panel \ International,sShortDate,dd / MM / yyyy)

解决方案

两件事:

1)你的代码无法编译。 ShortDatePattern不是方法,也不能被调用。它只是一个字符串。

2)你正在使用 CurrentUICulture - 你想要 CurrentCulture

 Label1.Text = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern; 

应该可以工作。


< blockquote>您无需更改系统短日期格式!您可以以任何所需的格式显示日期。请参阅:

标准日期和时间格式字符串| Microsoft Docs [ ^ ]

自定义日期和时间格式字符串| Microsoft Docs [ ^ ]

DateTime.ToString方法(系统) [ ^ ]



 ' 自定义日期格式 
Dim cdf 作为 字符串 = < span class =code-string> dd-MM-yyyy
' India CultureInfo
Dim hin 作为 Globalization.CultureInfo = Globalization.Cultur eInfo.CreateSpecificCulture( HI-in
' 当前日期和时间
Dim curdate As DateTime = DateTime.Now

Console.WriteLine(curdate.ToString(cdf,hin))
' 显示:04-06-2018


hello sir
how can I get my system short date format in a label in vb. net. I try this code :

Label1.Text = System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern()


but show wrong data. all time show "M/d/yyyy" format.
I change it(to "dd/MM/yyyy") manually and by coding result is same("M/d/yyyy") please help me.....

What I have tried:

Label1.Text = System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern()



For Change the Format:

Microsoft.Win32.Registry.SetValue("HKEY_CURRENT_USER\Control Panel\International", "sShortDate", "dd/MM/yyyy")

解决方案

Two things:
1) Your code won't compile. ShortDatePattern is not a method, and can't be called. It's just a string.
2) You are using CurrentUICulture - you want CurrentCulture

Label1.Text = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;

Should work.


You don't need to change system short date format! You can display a date in any format you want. See:
Standard Date and Time Format Strings | Microsoft Docs[^]
Custom Date and Time Format Strings | Microsoft Docs[^]
DateTime.ToString Method (System)[^]

'custom date format
Dim cdf As String = "dd-MM-yyyy"
'India CultureInfo
Dim hin As Globalization.CultureInfo = Globalization.CultureInfo.CreateSpecificCulture("HI-in")
'current date and time
Dim curdate As DateTime = DateTime.Now

Console.WriteLine(curdate.ToString(cdf, hin))
'displays: 04-06-2018


这篇关于如何在vb中的标签中获取我的系统短日期格式。净的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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