VB.Net Tutorial/Date Time/Now — различия между версиями

Материал из VB Эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Текущая версия на 12:54, 26 мая 2010

Current time

Public Class Tester
    Public Shared Sub Main
        Console.WriteLine(Now.ToLongTimeString)
    End Sub
End Class
9:07:41 PM

Different parts of Now

Public Class Tester
    Public Shared Sub Main
        Dim rightNow As Date = Now
        Dim hourNow As Integer = rightNow.Hour
        Dim minuteNow As Integer = rightNow.Minute
        Dim secondNow As Integer = rightNow.Second
        Dim millisecondNow As Integer = rightNow.Millisecond
        Dim results As String = String.Format( _
           "Hour: {1}{0}Minute: {2}{0}Second: " & _
           "{3}{0}Millisecond: {4}", vbNewLine, _
           hourNow, minuteNow, secondNow, millisecondNow)
        Console.WriteLine(results)

    End Sub
End Class
Hour: 21
Minute: 9
Second: 39
Millisecond: 640

Now.Ticks

Public Class Tester
    Public Shared Sub Main
        Dim lastTicks As Long
        Dim numTicks As Long
        Dim endTime As Date
        Dim results As String
        endTime = Now.AddSeconds(1)
        Do
            If (Now.Ticks <> lastTicks) Then
                numTicks += 1
                lastTicks = Now.Ticks
            End If
        Loop Until (Now > endTime)
        results = "Now.Ticks:  " & Now.Ticks.ToString & vbNewLine & _
           "Number of updates per second: " & numTicks.ToString
        Console.WriteLine(results)
    End Sub
End Class
Now.Ticks:  633145145786406250
Number of updates per second: 65