The local computer time including seconds

nickmarshall
nickmarshall used Ask the Experts™
on
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.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
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 ..
Dim sFolderPath As String = "C:\Test"
Dim sFileName As String = String.Format("{0}\{1}.extention",sFolderPath,now.Ticks.ToString)

Author

Commented:
Hi,

thanks for this.  Would I also be able to add in front the date in numerices ie; 01112006
Senior Software Engineer
Commented:
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...)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial