用vb 或vb.net 获得从1970年 01月01日 到现在累计的秒数

用vb 或vb.net 获得从1970年 01月01日 到现在累计的秒数,第1张

Private Sub Button2_Click(ByVal sender As SystemObject, ByVal e As SystemEventArgs) Handles Button2Click

Dim d1970 As New SystemDateTime(1970, 1, 1, 0, 0, 0, 0)

Dim iSeconds As Long

iSeconds = (NowTicks - d1970Ticks) / 10000000

MsgBox(iSeconds)

End Sub

您可以用API函数GetSystemTime或GetLocalTime返回的SYSTEMTIME结构的参数获得系统日期和精确到毫秒的系统时间。

GetSystemTime返回UTC时间,GetLocalTime返回当地时间。

如下例:

Private Declare Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)

Private Declare Sub GetLocalTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)

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 Sub Timer1_Timer()

Dim s As String

Dim sys As SYSTEMTIME

GetSystemTime sys ‘或者 GetLocalTime sys

s= CStr(syswYear) + "," + CStr(syswMonth) + "," + CStr(syswDay)

Label1Caption = s

s1= CStr(syswHour) + ":" + CStr(syswMinute) + ":" + CStr(syswSecond) + ":" + CStr(syswMilliseconds)

‘ 或者s = Time$ + " : " + CStr(syswMilliseconds)

Label2Caption = s1

End Sub

详细信息请参考以下链接:

GetSystemTime

>

#include <timeh> void main() { time_t seconds; struct tm timeinfo; int sec; seconds = time (NULL); timeinfo = localtime ( &seconds ); sec= timeinfo->tm_hour; printf("%d:",sec); // 小时sec= timeinfo->tm_min; printf("%d:",sec); // 分sec= timeinfo->tm_sec; printf("%d\n",sec); // 秒}

'在窗体上加入Label1与Timer1控件,然后把下面的代码粘贴,就可以运行了

Option Explicit

Private Const OneDay As Date = #8/8/2010# '目标时间,月/日/年

Private Sub Form_Load()

Timer1Interval = 1000

Timer1Enabled = True

Label1AutoSize = True

Timer1_Timer

End Sub

Private Sub Timer1_Timer()

Dim d As Long, h As Long, m As Long, s As Long

s = DateDiff("s", Now, OneDay)

If s < 0 Then

Label1Caption = "现在已过了" & FormatDateTime(OneDay, vbLongDate) & ",所以无法再倒时计。"

Timer1Enabled = False

Exit Sub

End If

d = s \ 86400

h = (s \ 3600) Mod 24

m = (s Mod 3600) \ 60

s = s Mod 60

Label1Caption = "距离" & FormatDateTime(OneDay, vbLongDate) & "还有:" & d & "天" & h & "小时" & m & "分" & s & "秒"

End Sub

以上就是关于用vb 或vb.net 获得从1970年 01月01日 到现在累计的秒数全部的内容,包括:用vb 或vb.net 获得从1970年 01月01日 到现在累计的秒数、vb怎样通过简单语句输出输出现在的毫秒数不用定义新的数据类型的,谢谢、VB输入小时,分,秒,化成多少秒,原代码等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/9463588.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-28
下一篇 2023-04-28

发表评论

登录后才能评论

评论列表(0条)

保存