vb3:更改为语言环境日期格式
vb3: change to locale date format
我在将日期设置为 31/12/2200 的 vb3 代码中有一个错误,并跳出一个错误,告诉我格式与语言环境机器不同。
解决方案是手动设置 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
我在将日期设置为 31/12/2200 的 vb3 代码中有一个错误,并跳出一个错误,告诉我格式与语言环境机器不同。
解决方案是手动设置 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