vb.net当前时分秒的简单介绍
vb .net获取时间的问题
格式化成String
创新互联公司是专业的丹凤网站建设公司,丹凤接单;提供网站设计制作、成都做网站,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行丹凤网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!
Console.WriteLine(DateTime.Now.ToString("hh:mm:ss"))
获取单个变量的值
Dim h As Integer = DateTime.Now.Hour '时
Dim m As Integer = DateTime.Now.Minute '分
Dim s As Integer = DateTime.Now.Second '秒
vb.net datetime怎么显示时分秒
将datePicker设置为该日期,这样就可以确保每次从nib中加载此视图时,选取器都会重置为当前得日期和时间就可以了。
vb.net中怎么获取日期中的年月日时分秒
Dim ThisDay As String = Format(Now, "yyyy-MM-dd") '获得当前日期字符串
Dim ThisDateTime As DateTime = Convert.ToDateTime(ThisDay) '当前日期转换成DateTime
Dim ThisWeekDay As Integer = ThisDateTime.DayOfWeek '获得当前日期是星期几
Dim differadd As Integer = 1 - ThisWeekDay '相差的天数(星期1与当前星期几相差的天数)
Dim MyAdd As New TimeSpan(differadd, 0, 0, 0)
Dim MyYear As Integer = Format(Now, "yyyy") '获取当前日期的年份
Dim MyMonth As Integer = Format(Now, "MM") '获取当前日期的月份
Dim MyDay As Integer = Format(Now, "dd") '获取当前日期是几号
Dim MyToday As DateTime = New DateTime(MyYear, MyMonth, MyDay)
Dim Yourday As DateTime = MyToday.Add(MyAdd)
MsgBox("本周星期一的日期是:" Yourday)
vb.net 时间统计问题
一楼风中的奶牛的做法很棒,建议楼主采纳他的回答。
只是其中有一个Bug,就是“倒数第二次累计分钟数为59,累计秒数达到60的时候,会出现**:60:**”。例如{"10:57:35", "2:02:51"},我这里做了修改,供参考。
另外,AddByInts中不需要进行循环和Select判断,可以简化。
同时,为了说明类和结构的关系,这里改用类。
也请一楼风中的奶牛勿怪罪在下啊!
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Dim str As String() = {"10:30:35", "2:02:51", "17:00:35", "2:02:51"}
Dim str As String() = {"10:57:35", "2:02:51"}
Dim time As TimeSerial = New TimeSerial
For Each dt As String In str
time.Add(dt)
Next
MsgBox(time.ToString)
End Sub
End Class
Public Class TimeSerial
Public Hour As Integer ' 时间的小时部分
Public Minute As Integer ' 时间的分钟部分
Public Second As Integer ' 时间的秒钟部分
' 合并添加新的时间值
' param name="value"文本时间格式(00:00:00)/param
Public Sub Add(ByVal value As String)
Dim arr As String() = Split(value, ":")
Dim dts(arr.Length - 1) As Integer
For i As Integer = 0 To arr.Length - 1
dts(i) = CInt(Val(arr(i)))
Next
AddByInts(dts)
End Sub
' 合并添加新的时间值
' param name="value"时间值(仅计算:时、分、秒)/param
Public Sub Add(ByVal value As Date)
Dim dts(2) As Integer
dts(0) = value.Hour
dts(1) = value.Minute
dts(2) = value.Second
AddByInts(dts)
End Sub
Private Sub AddByInts(ByVal value As Integer())
Second += value(2)
If Second = 60 Then
Minute += Int(Second / 60)
Second = Second Mod 60
End If
Minute += value(1)
If Minute = 60 Then
Hour += Int(Minute / 60)
Minute = Minute Mod 60
End If
Hour += value(0)
End Sub
' 获取时间的文本格式(00:00:00)
Public Overrides Function ToString() As String
Return Hour ":" Minute ":" Second
End Function
End Class
vb.net获取年,月,日,时,分,秒
不是 有 函数嘛?
now() 就是 吧
取得 后 再 分离出你所需的,分别赋值 就行了,当然 还是 有 函数的
分享名称:vb.net当前时分秒的简单介绍
文章出自:http://scyanting.com/article/hhcgos.html