「VB.NET」現在の日時から年月日を取得する
書式
Public Shared ReadOnly Property Now As DateTime
コンピューター上の現在の日時を現地時刻で表した DateTime オブジェクトを取得します。
使用例
Module Module1
Public Sub Main()
Dim cft As DateTime = DateTime.Now
'年を取得
Console.WriteLine("年: " & cft.Year)
'月を取得
Console.WriteLine("月: " & cft.Month)
'日を取得
Console.WriteLine("日: " & cft.Day)
Console.ReadKey()
End Sub
End Module
Module Module1
Public Sub Main()
Dim cft As DateTime = DateTime.Now
'年を取得
Console.WriteLine("年: " & cft.Year)
'月を取得
Console.WriteLine("月: " & cft.Month)
'日を取得
Console.WriteLine("日: " & cft.Day)
Console.ReadKey()
End Sub
End Module
Module Module1 Public Sub Main() Dim cft As DateTime = DateTime.Now '年を取得 Console.WriteLine("年: " & cft.Year) '月を取得 Console.WriteLine("月: " & cft.Month) '日を取得 Console.WriteLine("日: " & cft.Day) Console.ReadKey() End Sub End Module
実行結果
年: 2022
月: 1
日: 19