Menuへ
Format関数を使用した各種日付の表示





現在の時間を、Format関数を使用し、いろいろな形式で表示させてみます。
コード
Private Sub CommandButton1_Click()
   '各種形式で日付、時刻を表示します。
    Range("B10").Value = Format(Now, "yyyy.mm.dd")
    Range("B11").Value = Format(Now, "yyyy.m.d")
    Range("B12").Value = Format(Now, "yy.mm.dd")
    Range("B13").Value = Format(Now, "yy.m.d")
    Range("B14").Value = Format(Now, "'yy.mm.dd")
    Range("B15").Value = Format(Now, "'yy.m.d")
    Range("B16").Value = Format(Now, "yyyy/mm/dd")
    Range("B17").Value = Format(Now, "yyyy/m/d")
    Range("B18").Value = Format(Now, "yy/mm/dd")
    Range("B19").Value = Format(Now, "yy/m/d")
    Range("B20").Value = Format(Now, "gee.mm.dd")
    Range("B21").Value = Format(Now, "gee.m.d")
    Range("B22").Value = Format(Now, "e.mm.dd")
    Range("B23").Value = Format(Now, "e.m.d")
    Range("B24").Value = Format(Now, "ggee.mm.dd")
    Range("B25").Value = Format(Now, "ggge.m.d")
    Range("B26").Value = Format(Now, "yy年mm月dd日")
    Range("B27").Value = Format(Now, "yy年m月d日")
    Range("B28").Value = Format(Now, "yyyy年mm月dd日")
    Range("B29").Value = Format(Now, "gee年mm月dd日")
    Range("B30").Value = Format(Now, "gggee年mm月dd日")
    Range("B31").Value = Format(Now, "mm月dd日")
End Sub

実行結果
コマンドボタンをクリックすると、B10から様々な形式で日付が表示されます。


2007.02.26
2007.2.26
07.02.26
07.2.26
07.02.26
07.2.26
2007/2/26
2007/2/26
2026/7/2
2026/7/2
H19.02.26
H19.2.26
19.02.26
19.2.26
平19.02.26
平成19.2.26
07年02月26日
07年2月26日
2007年02月26日
H19年02月26日
平成19年02月26日
2月26日




Topへ