vb中获取系统当前的时间用函数 now() 就可以。另外还有相关的时间 date() time()
创新互联公司是由多位在大型网络公司、广告设计公司的优秀设计人员和策划人员组成的一个具有丰富经验的团队,其中包括网站策划、网页美工、网站程序员、网页设计师、平面广告设计师、网络营销人员及形象策划。承接:成都做网站、成都网站建设、成都外贸网站建设、网站改版、网页设计制作、网站建设与维护、网络推广、数据库开发,以高性价比制作企业网站、行业门户平台等全方位的服务。
now()获取系统当前日期和时间,如:2015-12-12 22:23:34
time()获取系统的时间,如:22:23:34不显示当前日期
date()获得系统的日期,如:2015-12-12
Private Sub Command1_Click()
MsgBox Now()
MsgBox Time()
MsgBox Date
End Sub
用大写的H可以显示24小时制:
(Format(DateTime.Now, "yyyyMMddHHmmss")).ToString
两种方式自己选用
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim s As String
s = DateTime.Today.Year()
s = s DateTime.Today.Month()
s = s DateTime.Today.Day()
s = s DateTime.Now.Hour()
s = s DateTime.Now.Minute()
s = s DateTime.Now.Second()
MsgBox(s, vbDefaultButton1, Now())
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim s As String
s = Format(Now(), "yyyymmddhhmmss")
MsgBox(s, vbYes, Now())
End Sub
Public Class Form1
Private Function ZToFSAll(ByVal ZT As Long) As String
'全存样式
'从天,时,分,秒整合为秒
Dim T, S, F, M As Integer '天,时,分,秒
Dim T1, S1 As Integer '天,时,分,秒
Dim M1 As String
T = ZT \ 86400
T1 = ZT Mod 86400
S = T1 \ 3600
S1 = T1 Mod 3600
F = S1 \ 60
M = S1 Mod 60
If M 10 Then
M1 = "0" M
Else
M1 = M
End If
ZToFSAll = T "天" S "小时" F "分钟" M1 "秒"
End Function
Private Function ZToFSQS(ByVal ZT As Long) As String
'缺损样式
'从秒分解为天,时,分,秒
Dim T, S, F, M As Integer '天,时,分,秒
Dim T1, S1 As Integer '天,时,分,秒
Dim T2, S2, F2, M2 As String '天,时,分,秒
T = ZT \ 86400
T1 = ZT Mod 86400
S = T1 \ 3600
S1 = T1 Mod 3600
F = S1 \ 60
M = S1 Mod 60
If T = 0 Then
T2 = ""
Else
T2 = T "天"
End If
If S = 0 Then
S2 = ""
Else
S2 = S "小时"
End If
If F = 0 Then
F2 = ""
Else
F2 = F "分钟"
End If
M2 = M "秒"
ZToFSQS = T2 S2 F2 M2
End Function
Private Function FSoZT(ByVal T As Integer, ByVal S As Int16, ByVal F As Int16, ByVal M As Int16) As Long
'从天,时,分,秒分解为秒
'T, S, F, M分别为天,时,分,秒
FSoZT = T * 86400 + S * 3600 + F * 60 + M
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = ZToFSQS(520354) '值为:6天32分钟34
TextBox1.Text = ZToFSAll(520354) '值为:6天0小时32分钟34秒
TextBox1.Text = FSoZT(6, 0, 32, 34) '值为:520354
End Sub。
假设你得到 N 秒
那么,一个小时就是 3600 秒,一分钟就是 60 秒,我们就可以这样子分割出来 :
小时 hour = N / 3600;
分钟 minute = ( N - ( hour * 3600 ) ) / 60;
秒 second = N - ( hour * 3600 + minute * 60 );
然后自己按照 hour : minute : second 的格式打印出来就行了 。
文章标题:关于vb.net获得小时的信息
转载注明:https://www.cdcxhl.com/article4/dseppoe.html
成都网站建设公司_创新互联,为您提供网站导航、营销型网站建设、服务器托管、网站收录、商城网站、响应式网站
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联