[VB.NET]String.Format()で年月日を表示するサンプル

2021年4月26日

書式を指定
Public Shared Function Format (format As String, ParamArray args As Object()) As String
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Module ModuleTest
Sub Main()
Dim cftA As String =
String.Format("{0}年{1}月{2}日", 2021, 6, 17)
Console.WriteLine(cftA)
Dim cftB As String =
String.Format("{0}/{1}/{2}", 2021, 6, 17)
Console.WriteLine(cftB)
Dim cftC As String =
String.Format("{0}年{1}月{2}日{3}時{4}分{5}秒", 2021, 6, 6, 17, 8, 21)
Console.WriteLine(cftC)
Dim cftD As String =
String.Format("{0}/{1}/{2} {3}:{4}:{5}", 2021, 6, 6, 17, 8, 21)
Console.WriteLine(cftD)
End Sub
End Module
Module ModuleTest Sub Main() Dim cftA As String = String.Format("{0}年{1}月{2}日", 2021, 6, 17) Console.WriteLine(cftA) Dim cftB As String = String.Format("{0}/{1}/{2}", 2021, 6, 17) Console.WriteLine(cftB) Dim cftC As String = String.Format("{0}年{1}月{2}日{3}時{4}分{5}秒", 2021, 6, 6, 17, 8, 21) Console.WriteLine(cftC) Dim cftD As String = String.Format("{0}/{1}/{2} {3}:{4}:{5}", 2021, 6, 6, 17, 8, 21) Console.WriteLine(cftD) End Sub End Module
Module ModuleTest
      Sub Main()

            Dim cftA As String =
                  String.Format("{0}年{1}月{2}日", 2021, 6, 17)
            Console.WriteLine(cftA) 

            Dim cftB As String =
                  String.Format("{0}/{1}/{2}", 2021, 6, 17)
            Console.WriteLine(cftB)

            Dim cftC As String =
                  String.Format("{0}年{1}月{2}日{3}時{4}分{5}秒", 2021, 6, 6, 17, 8, 21)
            Console.WriteLine(cftC) 

            Dim cftD As String =
                  String.Format("{0}/{1}/{2} {3}:{4}:{5}", 2021, 6, 6, 17, 8, 21)
            Console.WriteLine(cftD) 
      End Sub
End Module

実行結果
2021年6月17日
2021/6/17
2021年6月6日17時8分21秒
2021/6/6 17:8:21

VB.net

Posted by arkgame