「VB.NET」日付文字列をyyyy/mm/dd形式に変換する

書式
Dim 変数名A As String = “文字列"
Dim 変数名B As Integer = Integer.Parse(変数名A)
Dim cft As String = 変数名B.ToString(“0000/00/00")
数値型へ変換した後に .ToString(“0000/00/00") で変換します
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Module Module1
Public Sub Main()
'変換元の日付文字列
Dim strA As String = "20220114"
'日付文字列をInteger型へ変換
Dim res As Integer = Integer.Parse(strA)
'yyyy/mm/dd型式に変換
Dim cft As String = res.ToString("0000/00/00")
'文字列を出力
Console.WriteLine("変換結果1:" & cft)
Dim strAA As Integer = 56789123
Dim cft2 As String = strAA.ToString("0000/00/00")
'文字列を出力
Console.WriteLine("変換結果2:" & cft2)
Console.ReadKey()
End Sub
End Module
Module Module1 Public Sub Main() '変換元の日付文字列 Dim strA As String = "20220114" '日付文字列をInteger型へ変換 Dim res As Integer = Integer.Parse(strA) 'yyyy/mm/dd型式に変換 Dim cft As String = res.ToString("0000/00/00") '文字列を出力 Console.WriteLine("変換結果1:" & cft) Dim strAA As Integer = 56789123 Dim cft2 As String = strAA.ToString("0000/00/00") '文字列を出力 Console.WriteLine("変換結果2:" & cft2) Console.ReadKey() End Sub End Module
Module Module1

    Public Sub Main()

        '変換元の日付文字列
        Dim strA As String = "20220114"


        '日付文字列をInteger型へ変換
        Dim res As Integer = Integer.Parse(strA)

        'yyyy/mm/dd型式に変換
        Dim cft As String = res.ToString("0000/00/00")

        '文字列を出力
        Console.WriteLine("変換結果1:" & cft)

        Dim strAA As Integer = 56789123
        Dim cft2 As String = strAA.ToString("0000/00/00")
        '文字列を出力
        Console.WriteLine("変換結果2:" & cft2)


        Console.ReadKey()
    End Sub

End Module

実行結果
変換結果1:2022/01/14
変換結果2:5678/91/23

VB.net

Posted by arkgame