VB.Net by API/System/DateTime

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

DateTime.DayOfWeek

  
Imports System.IO
Module Module1

    Sub Main()
        Dim DateInfo As New DateTime(Now.Ticks)
        Console.WriteLine("Date: " & DateInfo.Month & "/" & _
           DateInfo.Day & "/" & DateInfo.Year)
        Console.WriteLine("Date: " & DateInfo.ToLongDateString())
        Console.WriteLine("Today is: " & DateInfo.DayOfWeek)
        Console.WriteLine("Days in April, 2002: " & DateInfo.DaysInMonth(2002, 4))
    End Sub
End Module


DateTime.IsLeapYear

  
Imports System.IO
Module Module1
    Sub Main()
        Dim Dt As DateTime = Now()

        If (Dt.IsLeapYear(Dt.Year)) Then
            Console.WriteLine("This is a leap year")
        Else
            Console.WriteLine("This is not a leap year")
        End If
    End Sub
End Module


DateTime.Second

  
Imports System
Public Class MainClass
    Shared Sub Main(ByVal args As String())
       Dim currentTime as System.DateTime = System.DateTime.Now
       Console.WriteLine("currentTime Year :" & currentTime.Year)
       Console.WriteLine("currentTime Month:" &  currentTime.Month)
       Console.WriteLine("currentTime Date:" & currentTime.Date)
       Console.WriteLine("currentTime Hour:" & currentTime.Hour)
       Console.WriteLine("currentTime Minute:" & currentTime.Minute)
       Console.WriteLine("currentTime Second:" & currentTime.Second)
    End Sub
End Class


DateTime.Subtract

  
public class Test
  
   public Shared Sub Main
        Dim start_time As DateTime
        Dim stop_time As DateTime
        Dim elapsed_time As TimeSpan
        Dim num_items As Integer = 10000
        Dim array1(0 To num_items - 1) As Integer
        start_time = Now
        For i As Integer = 0 To num_items - 1
            array1(i) = i
        Next i
        stop_time = Now
        elapsed_time = stop_time.Subtract(start_time)
        Console.WriteLine(elapsed_time.TotalSeconds())

        Erase array1
   End Sub
   
End class


DateTime.ToUniversalTime()

  
public class Test
   public Shared Sub Main
        Dim D As DateTime
        D = Now()
    
        Console.WriteLine(D.ToUniversalTime().GetType().Name)
    
        Console.WriteLine("UTC-LocalTime=" + D.ToUniversalTime().Subtract(D).ToString())
    
        Console.WriteLine("Ticks since 12:00AM January 1, 1 CE="+ Now().Ticks().ToString())
   End Sub
End class


DateTime.UtcNow()

  

Public Class MainClass
   Public Shared Sub Main()
        "Date Time examples
        Dim dteNow As Date = Now()
        Dim dteToday As Date = Today()
        Dim dteGMT As DateTime = DateTime.UtcNow()
        Console.WriteLine(dteNow)
        Console.WriteLine(dteToday)
        Console.WriteLine(dteGMT)
        
   End Sub
End Class


DateTime.Year

  
Imports System
Public Class MainClass
    Shared Sub Main(ByVal args As String())
       Dim currentTime as System.DateTime = System.DateTime.Now
       Console.WriteLine("currentTime Year :" & currentTime.Year)
       Console.WriteLine("currentTime Month:" &  currentTime.Month)
       Console.WriteLine("currentTime Date:" & currentTime.Date)
       Console.WriteLine("currentTime Hour:" & currentTime.Hour)
       Console.WriteLine("currentTime Minute:" & currentTime.Minute)
       Console.WriteLine("currentTime Second:" & currentTime.Second)
    End Sub
End Class


New DateTime

  

public class Test
   public Shared Sub Main
    Dim D As New DateTime(10000333333333333)
    Console.WriteLine("10000 ticks is " + D.Date())
   End Sub
End class