第一个参数指定一个完整的文件路径及名称,第二个参数指定要获取创建时间(theCreateTime),访问时间(theLastAccessTime)还是最后修改时间(theLastWriteTime),缺省为创建时间
如:获取文件创建时间
Private Sub Command1_Click()
MsgBox GetTime("c:\abctxt")
End Sub你是指Internet上的国际标准时间吗。
先加入控件 AxWinsock1 在Com中MicrosoftWinsock
Public Class Form1
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Integer)
Dim NoSrv As Boolean
Dim TimeFromNet As String
Dim OldTime As Date
Dim NewTime As Date
Dim MyDate As Date
Private Sub Button1_Click(ByVal sender As SystemObject, ByVal e As SystemEventArgs) Handles Button1Click
If AxWinsock1CtlState <> MSWinsockLibStateConstantssckClosed Then AxWinsock1Close()
AxWinsock1Protocol = MSWinsockLibProtocolConstantssckTCPProtocol
NetTime(">可以禁止修改系统时间即可,代码如下,源码可以发给你,你的邮箱是?窗体form1(需要一个timer控件,interval=1000):
窗体代码Private Sub Form_Load()
Timer1_Timer
RegisterWindow Mehwnd '为窗口设置子类
End SubPrivate Sub Form_Unload(Cancel As Integer)
unRegisterWindow Mehwnd '取消窗口的子类
End SubPrivate Sub Timer1_Timer()
OldTime = Now
End Sub'模块modle1:Option Explicit
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Long
Public OldTime As String
Public ChangeFlag As Boolean
Public Const WM_TIMECHANGE As Long = &H1E '当系统的时间变化时发送此消息给所有顶级窗口
Public oldproc As Long
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Declare Function SetLocalTime Lib "kernel32" (lpSystemTime As SYSTEMTIME) As LongPublic Function RegisterWindow(hwnd As Long) As Long
If hwnd <> 0 Then
oldproc = SetWindowLong(hwnd, -4, AddressOf WinProc)
End If
End Function
Public Function unRegisterWindow(hwnd As Long) As LongIf hwnd <> 0 Then
SetWindowLong hwnd, -4, oldproc
End IfEnd Function
Public Function WinProc(ByVal hwnd As Long, ByVal msg As Long, ByVal lpara As Long, ByVal wpara As Long) As LongDim i, myttIf msg = WM_TIMECHANGE And ChangeFlag = False Then '系统时间被修改了而且不是本程序修改的ChangeFlag = True '本程序要修改系统时间Call SetToOldTime '修改系统时间Exit FunctionEnd If
ChangeFlag = FalseWinProc = CallWindowProc(oldproc, hwnd, msg, lpara, wpara)
End Function
Public Function SetToOldTime() As String '将时间恢复到设置前的状态
Dim tmp As String
tmp = OldTime '从保存的时间中取出修改前的系统时间
Dim lpSystemTime As SYSTEMTIME
lpSystemTimewYear = Year(tmp) '取出年份
lpSystemTimewMonth = Month(tmp) '取出月份
lpSystemTimewDayOfWeek = -1
lpSystemTimewDay = Day(tmp) '取出日
lpSystemTimewHour = Hour(tmp) '取出小时
lpSystemTimewMinute = Minute(tmp) '取出分钟
lpSystemTimewSecond = Second(tmp) '取出秒
lpSystemTimewMilliseconds = 0
'set the new time
SetLocalTime lpSystemTimeEnd Functionnow() 可以获取当前的时间。
可以使用 print now() 进行测试。输出当前时间。
想用文本保存。
那就:
open apppath & "\timetxt" for output as #1
print #1,now()
closeVB里有好多时间函数,使用方法和excel类似,直接调用就好了,比如now显示当前时间,today表示当前日期,又如year年,month月,day日,hour小时(24小时制),minute分,second秒;
另外要想获得想要的时间格式,你需要一个格式函数Formart(),表示为formart(date,formart of date),比如我想获得今天的日期并且用这种格式2015-08-31,那么函数是formart(now,"ddddd"),这里的ddddd就是格式符,想要获得全部的格式符可以百度“formart()函数使用“,我这里就不引用了,希望以上内容对你有帮助Imports vb = MicrosoftVisualBasic
Public Class Form1
Private Sub Button1_Click(ByVal sender As SystemObject, ByVal e As SystemEventArgs) Handles Button1Click
Dim obj, OBJStatus, url, GetText, i
Dim Retrieval
url = ">
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)