Vb6 vb3:更改为区域设置日期格式

Vb6 vb3:更改为区域设置日期格式,vb6,vb5,Vb6,Vb5,我在vb3代码中有一个错误,我将日期设置为31/12/2200,并跳转一个错误,告知格式与语言环境机器不同 解决方案是手动设置12/31/2200,但我感兴趣的是获取机器的区域设置以自动设置 如何在vb3中更改为区域设置日期?我无法帮助您使用vb3。我已经很多年没看到了。我可以给你一些在VB5/VB6中工作的东西。我不知道它转换到VB3的效果如何。希望如果它需要工作,你可以把它翻译成VB3或找人可以。您需要添加适当的错误处理 Private Declare Function GetLocaleI

我在vb3代码中有一个错误,我将日期设置为31/12/2200,并跳转一个错误,告知格式与语言环境机器不同

解决方案是手动设置12/31/2200,但我感兴趣的是获取机器的区域设置以自动设置


如何在vb3中更改为区域设置日期?

我无法帮助您使用vb3。我已经很多年没看到了。我可以给你一些在VB5/VB6中工作的东西。我不知道它转换到VB3的效果如何。希望如果它需要工作,你可以把它翻译成VB3或找人可以。您需要添加适当的错误处理

Private Declare Function GetLocaleInfo Lib "kernel32" Alias "GetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String, ByVal cchData As Long) As Long
Private Const LOCALE_USER_DEFAULT = &H400
Private Const LOCALE_SSHORTDATE = &H1F ' short date format string
Private Const LOCALE_SLONGDATE = &H20 ' long date format string

Private Sub Form_Load()
    Dim strMsg As String

    strMsg = "Short Date Format: " & FormatShortDate(DateTime.Now)
    strMsg = strMsg & vbCrLf & "Long Date Format: " & FormatLongDate(DateTime.Now)

    MsgBox strMsg

End Sub

Private Function FormatShortDate(ByVal vDate As Date) As String
    Dim strShortDateFormat As String
    Dim lngRet As Long
    Dim strReturn As String

    'Get short date format
    strShortDateFormat = Space(255)
    lngRet = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, strShortDateFormat, Len(strShortDateFormat))
    strShortDateFormat = Left(strShortDateFormat, lngRet - 1)

    strReturn = Format$(vDate, strShortDateFormat)

    FormatShortDate = strReturn

End Function

Private Function FormatLongDate(ByVal vDate As Date) As String
    Dim strLongDateFormat As String
    Dim lngRet As Long
    Dim strReturn As String

    'Get long date format
    strLongDateFormat = Space(255)
    lngRet = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SLONGDATE, strLongDateFormat, Len(strLongDateFormat))
    strLongDateFormat = Left(strLongDateFormat, lngRet - 1)

    strReturn = Format$(vDate, strLongDateFormat)

    FormatLongDate = strReturn

End Function

我对vb3的印象是,作为一个16位的应用程序开发工具,它本身并没有区域设置意识,并且通常不能像@jac在这里所做的那样调用Windows api来执行这些区域设置操作。variable=“31/12/2000”应该是“12/31/2000”