2017-05-28 91 views
1

我试图确定从vb.net系统的日期格式,必须将其从命令提示符中显示的格式相匹配。如何确定用户的本地系统的日期格式

实施例,如果在命令提示符键入date(您可能需要运行它作为管理员) 它将输出的日期变化所需要的格式,以生效,与此类似:

The current date is: Sun 05/28/2017 Enter the new date: (mm-dd-yy)

我的任务栏中显示的当前日期也是05/28/2017

从vb.net,我需要找出所需的格式,在这种情况下是mm-dd-yy

我试图System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern()其输出dd/MM/yyyy不匹配的格式。

+0

我不知道这是肯定的,但是,考虑到要求输入输出格式不匹配的格式,我会说,该输入格式是恒定的,不依赖于文化。 – jmcilhinney

回答

0

得到它的工作使用这样的:

Private Function CheckDateFormat1() 
    Dim Format As String = DateTimeFormatInfo.CurrentInfo.ShortDatePattern 

    If Format.Contains("MMM") Then 
     Format = Format.Replace("MMM", "MM") 
    ElseIf Format.Contains("MMMM") Then 
     Format = Format.Replace("MMMM", "MM") 
    End If 

    If Format.Contains("dddd") Then 
     Format = Format.Replace("dddd", "dd") 
    End If 

    Return Format 
End Function 
0

通过窗口的官方文档上的“日期”命令去,那只是硬编码输出,并且只要他们是“/”,或将接受任何分隔符“”,‘ - ’。请参阅此处的文档: https://technet.microsoft.com/en-us/library/cc732776(v=ws.11).aspx

但是,System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern()命令应输出用户的当前本地系统日期格式;或MSDN文档错误。 https://msdn.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.shortdatepattern(v=vs.110).aspx

相关问题