Reynier
Reynier

Reputation: 2478

Format DateTime in C# to append to file name

I need to format current DateTime in this format dd-mm-yyyy-hh-mm-ss and don't know how to do it. I read on Internet and then write this code:

DateTime saveNow = DateTime.Now;
MessageBox.Show(String.Format("{0:u}", saveNow));

But this returns the date on this format:

2013-04-24 23:11:34Z

Can any help me? I need the first format to append to a file name I'm creating.

Upvotes: 4

Views: 9536

Answers (1)

AD.Net
AD.Net

Reputation: 13399

DateTime.Now.ToString("dd-MM-yyyy-hh-mm-ss")

More info here

Upvotes: 18

Related Questions