「VB.NET」書式を指定して日時を表示するサンプル
書式
Public Function ToString (format As String) As String
名前空間は、Systemです。
このインスタンスの数値を、指定したカルチャ固有の書式情報を使用して、
それと等価な文字列形式に変換します。
戻り値
formatで指定された、このインスタンスの値の文字列形式。
使用例
Public Sub Main()
Dim cftA As Integer = 20220213
Console.WriteLine(cftA.ToString("0000/00/00"))
Dim cftB As Integer = 20221116
Console.WriteLine(cftB.ToString("0000年00月00日"))
Dim cftC As Long = 20220706140721
Console.WriteLine(cftC.ToString("0000年00月00日00時00分00秒"))
Dim cftD As Long = 20220706180921
Console.WriteLine(cftD.ToString("0000/00/00 00:00:00"))
Console.ReadKey()
End Sub
実行結果
2022/02/13
2022年11月16日
2022年07月06日14時07分21秒
2022/07/06 18:09:21