|
Option Compare Database
Option Explicit
Public Declare Function GetUserDefaultLCID Lib "kernel32" () As Long
Public 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
Public Declare Function SetLocaleInfo Lib "kernel32" Alias "SetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String) As Long
'设置短日期格式
Public Const LOCALE_SSHORTDATE = &H1F
Public Const LOCALE_SDATE = &H1D
'下面的过程可以帮你达到目的
Sub setshortdate()
Dim llocal As Long
Dim sa As String
Dim lOk As Long
Dim setlocalinfo As Variant
On Error GoTo ErrShow
sa = Space(20)
llocal = GetUserDefaultLCID()
lOk = GetLocaleInfo(llocal, LOCALE_SSHORTDATE, ByVal sa, 20)
If Trim(sa) <> "yyyy-MM-dd" Then
MsgBox "您的系统日期不是(YYYY-MM-DD)格式,点击确定,自动更改格式"
'If MsgBox("您的系统日期不是(YYYY-MM-DD)格式,强烈建议您将它修改成该格式," & Chr(10) _
& "否则软件可能会出现运行障碍!" _
& Chr(10) & Chr(10) & "点击'是'将自动为您修改。", vbQuestion + vbYesNo, "忠告") = vbYes Then
sa = "yyyy-MM-dd"
llocal = GetUserDefaultLCID()
SetLocaleInfo llocal, LOCALE_SSHORTDATE, ByVal sa
'End If
End If
sa = Space(2)
lOk = GetLocaleInfo(llocal, LOCALE_SDATE, ByVal sa, 2)
If Trim(sa) <> "-" Then
sa = "-"
lOk = SetLocaleInfo(llocal, LOCALE_SDATE, ByVal sa)
End If
setlocalinfo = True
Exit Sub
ErrShow:
MsgBox "系统日期不能自动设置为(2002-01-01)的格式" & vbCrLf & "请用手工先把系统日期改为如(2002-01-01)的格式,再运行本系统!"
End Sub
|
|