0
0

More than 5 years have passed since last update.

VB.netでの日時、ミリ秒、フォーマット変換、おまけで乱数

Last updated at Posted at 2019-01-21
        Dim myRnd As String

        '--- 乱数初期化
        Randomize(Double.Parse(Format(Now(), "hhmmssfff")))  'fffはミリ秒3桁

        '4桁の乱数を作成
        For x = 1 To 4
            '0~9の範囲の乱数を取得して文字列として結合
            myRnd = myRnd & CStr(Int((9 - 0 + 1) * Rnd() + 0))
        Next x
        Dim strRes As String = "ABC-" & Format(CType(Now, Date), "yyyyMMddHHmmssfff") & "-" & myRnd


        strRes → ABC-20190121150037123-5678
                  a   b       c     d   e   

         -a  "ABC-"         固定値  
         -b  "20190121"    日付
         -c  "150037"      時刻
         -d  "123"         ミリ秒
         -e  "5678"        乱数
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0