Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format DateTime in C# to append to file name

Tags:

c#

.net

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.

like image 408
Reynier Avatar asked Dec 01 '22 19:12

Reynier


1 Answers

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

More info here

like image 93
AD.Net Avatar answered Dec 04 '22 07:12

AD.Net