VB.Net by API/System/Date — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 12:51, 26 мая 2010
Содержание
- 1 Date.AddDays
- 2 Date.AddMilliseconds
- 3 Date.AddMonths
- 4 Date.AddYears
- 5 Date.DayOfYear
- 6 Date.Millisecond
- 7 Date.op_Subtraction
- 8 Date.Parse
- 9 Date.ToLongDateString
- 10 Date.ToLongTimeString
- 11 Date.ToOADate
- 12 Date.ToShortDateString
- 13 Date.ToShortTimeString
- 14 Date.ToString
- 15 Date.ToUniversalTime
- 16 New Date(Int year, Int month, Int day)
- 17 New Date(Int year, Int month, Int day, Int hour, Int minute)
Date.AddDays
Public Class Tester
Public Shared Sub Main
Dim rightNow As Date = Now
Console.WriteLine("RightNow: " & rightNow.ToString)
Console.WriteLine("RightNow.AddYears(2): " & rightNow.AddYears(2))
Console.WriteLine("RightNow.AddMonths(3): " & rightNow.AddMonths(3))
Console.WriteLine("RightNow.AddDays(4): " & rightNow.AddDays(4))
End Sub
End Class
Date.AddMilliseconds
Public Class Tester
Public Shared Sub Main
Dim rightNow As Date = Now
Console.WriteLine("RightNow: " & rightNow.ToString)
" ----- Add time values.
Console.WriteLine("RightNow.AddHours(5): " & rightNow.AddHours(5))
Console.WriteLine("RightNow.AddMinutes(6): " & rightNow.AddMinutes(6))
Console.WriteLine("RightNow.AddSeconds(7): " & rightNow.AddSeconds(7))
Console.WriteLine("RightNow.AddMilliseconds(8000): " & rightNow.AddMilliseconds(8000))
End Sub
End Class
Date.AddMonths
Public Class Tester
Public Shared Sub Main
Dim rightNow As Date = Now
Console.WriteLine("RightNow: " & rightNow.ToString)
Console.WriteLine("RightNow.AddYears(2): " & rightNow.AddYears(2))
Console.WriteLine("RightNow.AddMonths(3): " & rightNow.AddMonths(3))
Console.WriteLine("RightNow.AddDays(4): " & rightNow.AddDays(4))
End Sub
End Class
Date.AddYears
public class Test
public Shared Sub Main
Dim Expiration As Date
Dim NewExpiration As Date
Expiration = #1/1/2005#
Expiration.AddYears(3)
NewExpiration = Expiration.AddYears(3)
Console.WriteLine("The new expiration date is: " & NewExpiration)
End Sub
End class
Date.DayOfYear
Imports System
Public Class MainClass
Shared Sub Main()
Dim dteData As Date
"Get the current date and time
dteData = Now
"Display the various properties
System.Console.WriteLine("Month: " & dteData.Month)
System.Console.WriteLine("Day: " & dteData.Day)
System.Console.WriteLine("Year: " & dteData.Year)
System.Console.WriteLine("Hour: " & dteData.Hour)
System.Console.WriteLine("Minute: " & dteData.Minute)
System.Console.WriteLine("Second: " & dteData.Second)
System.Console.WriteLine("Day of week: " & dteData.DayOfWeek)
System.Console.WriteLine("Day of year: " & dteData.DayOfYear)
End Sub
End Class
Date.Millisecond
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
Date.op_Subtraction
public class Test
public Shared Sub Main
Dim date1 As Date = #7/20/2004#
Dim date2 As Date = #8/7/2004#
Dim elapsed_time As TimeSpan
elapsed_time = Date.op_Subtraction(date2, date1)
Console.WriteLine(elapsed_time.Days.ToString)
End Sub
End class
Date.Parse
Public Class Tester
Public Shared Sub Main
Dim testDate As String
Dim results As New System.Text.StringBuilder
" ----- Test an invalid date.
testDate = "Febtember 43, 2007"
If (IsDate(testDate) = True) Then _
results.AppendLine(Date.Parse(testDate).ToString)
Console.WriteLine(results.ToString())
End Sub
End Class
Date.ToLongDateString
Public Class Tester
Public Shared Sub Main
Dim rightNow As Date = Now
Dim result As New System.Text.StringBuilder
result.AppendLine("""Now""...")
result.Append("ToString: ").AppendLine(rightNow.ToString)
result.Append("ToLongDateString: ")
result.AppendLine(rightNow.ToLongDateString)
result.Append("ToShortDateString: ")
result.AppendLine(rightNow.ToShortDateString)
result.Append("ToLongTimeString: ")
result.AppendLine(rightNow.ToLongTimeString)
result.Append("ToShortTimeString: ")
result.AppendLine(rightNow.ToShortTimeString)
result.Append("ToUniversalTime: ")
result.AppendLine(rightNow.ToUniversalTime)
result.AppendLine()
Console.WriteLine(result.ToString)
End Sub
End Class
Date.ToLongTimeString
Public Class Tester
Public Shared Sub Main
Dim rightNow As Date = Now
Dim result As New System.Text.StringBuilder
result.AppendLine("""Now""...")
result.Append("ToString: ").AppendLine(rightNow.ToString)
result.Append("ToLongDateString: ")
result.AppendLine(rightNow.ToLongDateString)
result.Append("ToShortDateString: ")
result.AppendLine(rightNow.ToShortDateString)
result.Append("ToLongTimeString: ")
result.AppendLine(rightNow.ToLongTimeString)
result.Append("ToShortTimeString: ")
result.AppendLine(rightNow.ToShortTimeString)
result.Append("ToUniversalTime: ")
result.AppendLine(rightNow.ToUniversalTime)
result.AppendLine()
Console.WriteLine(result.ToString)
End Sub
End Class
Date.ToOADate
public class Test
public Shared Sub Main
Dim D As Date = Now()
Dim F As Double = D.ToOADate()
Console.WriteLine(F)
End Sub
End class
Date.ToShortDateString
Public Class Tester
Public Shared Sub Main
Dim rightNow As Date = Now
Dim result As New System.Text.StringBuilder
result.AppendLine("""Now""...")
result.Append("ToString: ").AppendLine(rightNow.ToString)
result.Append("ToLongDateString: ")
result.AppendLine(rightNow.ToLongDateString)
result.Append("ToShortDateString: ")
result.AppendLine(rightNow.ToShortDateString)
result.Append("ToLongTimeString: ")
result.AppendLine(rightNow.ToLongTimeString)
result.Append("ToShortTimeString: ")
result.AppendLine(rightNow.ToShortTimeString)
result.Append("ToUniversalTime: ")
result.AppendLine(rightNow.ToUniversalTime)
result.AppendLine()
Console.WriteLine(result.ToString)
End Sub
End Class
Date.ToShortTimeString
Public Class Tester
Public Shared Sub Main
Dim rightNow As Date = Now
Dim result As New System.Text.StringBuilder
result.AppendLine("""Now""...")
result.Append("ToString: ").AppendLine(rightNow.ToString)
result.Append("ToLongDateString: ")
result.AppendLine(rightNow.ToLongDateString)
result.Append("ToShortDateString: ")
result.AppendLine(rightNow.ToShortDateString)
result.Append("ToLongTimeString: ")
result.AppendLine(rightNow.ToLongTimeString)
result.Append("ToShortTimeString: ")
result.AppendLine(rightNow.ToShortTimeString)
result.Append("ToUniversalTime: ")
result.AppendLine(rightNow.ToUniversalTime)
result.AppendLine()
Console.WriteLine(result.ToString)
End Sub
End Class
Date.ToString
Public Class Tester
Public Shared Sub Main
Dim rightNow As Date = Now
Dim result As New System.Text.StringBuilder
result.AppendLine("""Now""...")
result.Append("ToString: ").AppendLine(rightNow.ToString)
result.Append("ToLongDateString: ")
result.AppendLine(rightNow.ToLongDateString)
result.Append("ToShortDateString: ")
result.AppendLine(rightNow.ToShortDateString)
result.Append("ToLongTimeString: ")
result.AppendLine(rightNow.ToLongTimeString)
result.Append("ToShortTimeString: ")
result.AppendLine(rightNow.ToShortTimeString)
result.Append("ToUniversalTime: ")
result.AppendLine(rightNow.ToUniversalTime)
result.AppendLine()
Console.WriteLine(result.ToString)
End Sub
End Class
Date.ToUniversalTime
Public Class Tester
Public Shared Sub Main
Dim rightNow As Date = Now
Dim result As New System.Text.StringBuilder
result.AppendLine("""Now""...")
result.Append("ToString: ").AppendLine(rightNow.ToString)
result.Append("ToLongDateString: ")
result.AppendLine(rightNow.ToLongDateString)
result.Append("ToShortDateString: ")
result.AppendLine(rightNow.ToShortDateString)
result.Append("ToLongTimeString: ")
result.AppendLine(rightNow.ToLongTimeString)
result.Append("ToShortTimeString: ")
result.AppendLine(rightNow.ToShortTimeString)
result.Append("ToUniversalTime: ")
result.AppendLine(rightNow.ToUniversalTime)
result.AppendLine()
Console.WriteLine(result.ToString)
End Sub
End Class
New Date(Int year, Int month, Int day)
Public Class Tester
Public Shared Sub Main
Dim thirdOfJuly As Date = #7/3/1776 11:59:59 PM#
Dim fourthOfJuly As New Date(1776, 7, 4)
Dim inTheMorning As New Date(1776, 7, 4, 9, 45, 30)
Console.WriteLine( _
"The 3rd and 4th of July, 1776..." & _
vbNewLine & vbNewLine & _
"#7/3/1776 11:59:59 PM# ... " & _
thirdOfJuly.ToString & vbNewLine & _
"New Date(1776, 7, 4) ... " & _
fourthOfJuly.ToString & vbNewLine & _
"New Date(1776, 7, 4, 9, 45, 30) ... " & _
inTheMorning.ToString)
End Sub
End Class
New Date(Int year, Int month, Int day, Int hour, Int minute)
Public Class Tester
Public Shared Sub Main
Dim thirdOfJuly As Date = #7/3/1776 11:59:59 PM#
Dim fourthOfJuly As New Date(1776, 7, 4)
Dim inTheMorning As New Date(1776, 7, 4, 9, 45, 30)
Console.WriteLine( _
"The 3rd and 4th of July, 1776..." & _
vbNewLine & vbNewLine & _
"#7/3/1776 11:59:59 PM# ... " & _
thirdOfJuly.ToString & vbNewLine & _
"New Date(1776, 7, 4) ... " & _
fourthOfJuly.ToString & vbNewLine & _
"New Date(1776, 7, 4, 9, 45, 30) ... " & _
inTheMorning.ToString)
End Sub
End Class