VB.Net by API/System/Now

Материал из VB Эксперт
Версия от 12:51, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Now.DayOfWeek

  
Module Module1
    Sub Main()
        Dim DayOfWeek As Integer
        DayOfWeek = Now.DayOfWeek
        Select Case DayOfWeek
            Case 1
                Console.WriteLine("Sunday")
            Case 2
                Console.WriteLine("Monday")
            Case 3
                Console.WriteLine("Tuesday")
            Case 4
                Console.WriteLine("Wednesday")
            Case 5
                Console.WriteLine("Thursday")
            Case 6
                Console.WriteLine("Friday")
            Case 7
                Console.WriteLine("Saturday")
        End Select
    End Sub
End Module


Now.Ticks

  
Public Class Tester
    Public Shared Sub Main
        Dim ticksBefore As Long
        Dim ticksAfter As Long
        Dim tickSeconds As Double
        ticksBefore = Now.Ticks
        MsgBox("Press OK to see elapsed seconds")
        ticksAfter = Now.Ticks
        tickSeconds = (ticksAfter - ticksBefore) / 10000000.0
        Console.WriteLine("Elapsed seconds: " & tickSeconds.ToString())
    End Sub
End Class


Now.ToLongTimeString

  
 
Public Class Tester
    Public Shared Sub Main
        Console.WriteLine(Now.ToLongTimeString)
    End Sub
End Class


Now.ToString

  
Imports System
Imports System.Data
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Diagnostics
Imports System.Drawing.Printing
Imports System.ruponentModel

Public Class MainClass
    
    Shared Sub Main()
        Console.WriteLine(Now.ToString("h:mm:ss tt"))
    End Sub
    
End Class


Now.ToUniversalTime

  
Public Class Tester
    Public Shared Sub Main
        Dim phaseDay As Double
        Dim result As String
        phaseDay = MoonPhase(Now.ToUniversalTime)
        result = "UTC is now: " & _
           Now.ToUniversalTime.ToString("u") & vbNewLine & vbNewLine
        If (phaseDay < 0) Then
            result &= "Approx days until new moon: " & _
               (-phaseDay).ToString("F1")
        Else
            result &= "Approx days since new moon: " & _
               phaseDay.ToString("F1")
        End If
        Console.WriteLine(result)
    End Sub
    Public Shared Function MoonPhase(ByVal dateUtc As Date) As Double
        Dim days As Double = dateUtc.Subtract(#1/1/1600#).TotalDays
        Dim cycles As Double = days * 0.03386319 - 12.5
        Return Math.IEEERemainder(cycles, 1.0) * 29.53059
    End Function
End Class