The local computer time including seconds

Hi,

I need to create a unique filename based on the exact time ie;

03:13

to this...

031334

This is for a unique filename.
LVL 1
nickmarshallAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Ravi SinghConnect With a Mentor Senior Software EngineerCommented:
Try:

Dim FileName As String = Now.ToString("ddMMyyyy hhmmss")

(You can remove the space in the ToString parameter if you dont want to seperate the date and time...)
0
 
Kinger247Commented:
Could try something like :

        Dim FileName As String
        Dim RND As New System.Random

        FileName = Now.Hour.ToString.PadLeft(2, "0"c) & Now.Minute.ToString.PadLeft(2, "0"c) & Now.Second.ToString.PadLeft(2, "0"c) & RND.Next(1, 1000)

        Console.WriteLine(FileName)

this also adds a random number at the end ..
0
 
herreruudCommented:
Dim sFolderPath As String = "C:\Test"
Dim sFileName As String = String.Format("{0}\{1}.extention",sFolderPath,now.Ticks.ToString)
0
 
nickmarshallAuthor Commented:
Hi,

thanks for this.  Would I also be able to add in front the date in numerices ie; 01112006
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.