设置系统时间格式的代码
时 间:2016-09-13 15:24:21
作 者:爱吉瑞 ID:15524 城市:连云港
摘 要:在一些ACCESS程序中,我们需用记录当前操作的时间。但当系统设置的时间带上午、下午的格式时,我们应用DOCMD.RUNSQL 语句添加记录时(包含日期字段),系统往往会出错。于是,我们得手工修改系统自带的时间格式,而显得我们的程序不够专业。下面的代码提供了自动更改时间格式的一种方式。
正 文:
Option Compare Database
Public Const LOCALE_STIMEFORMAT = &H1003
Public Const LOCALE_SSHORTDATE = &H1F
Public Const WM_SETTINGCHANGE = &H1A
Public Const HWND_BROADCAST = &HFFFF&
Const SPI_SETDESKWALLPAPER = 20
Const SPIF_SENDCHANGE = &H2
Public Declare Function SetLocaleInfo Lib "kernel32" Alias "SetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String) As Boolean
Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function GetSystemDefaultLCID 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 SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam As Any, ByVal fuWinIni As Long) As Long
Public Sub setdateformat()
Dim dwLCID As Long, i As Long
Dim lpLCData As String * 255, cchData
cchData = Len(lpLCData)
dwLCID = GetSystemDefaultLCID()
i = SetLocaleInfo(dwLCID, LOCALE_STIMEFORMAT, "h:mm:ss") '设置时间格式
PostMessage HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0
SystemParametersInfo SPI_SETDESKWALLPAPER, 0, "", SPIF_SENDCHANGE
Debug.Print Time
End Sub
然后,在相应的窗口代码中调用setdateformat即可。
缺点:改好相应的格式(如"h:mm:ss”,需重新启动或注销系统再次打开程序方生效)
Access软件网官方交流QQ群 (群号:54525238) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- Access对子窗体数据进行批...(10.30)
- 最精简的组合框行来源数据快速输...(10.25)
- Access仿平台的多值选择器...(10.24)
- 【Access日期区间段查询】...(10.22)
- 【Access源码示例】VBA...(10.12)
- Access累乘示例,Acce...(10.09)
- 数值8.88,把整数8去掉,转...(10.08)
- 【Access自定义函数】一个...(09.30)
- 【Access选项卡示例】Ac...(09.09)
学习心得
最新文章
- 【Access IIF函数嵌套示例...(11.26)
- Access快速开发平台--使用组...(11.25)
- Access快速开发平台--对上传...(11.22)
- Access快速开发平台企业版--...(11.18)
- 不会用多表联合查询,多表查询没结果...(11.16)
- 【案例分享】主键字段值含有不间断空...(11.16)
- Access快速开发平台--后台D...(11.14)
- 微软Access邀测新Monaco...(11.12)
- Access列表框左右互选、列表框...(11.11)
- 高效率在导入数据前删除记录(11.10)