DateTime date1 = new DateTime(2010, 8, 18, 16, 32, 0);
// The example displays the following output, in this case for en-us culture:
//      8/18/2010 4:32:00 PM

ToString() method

In this example I use DateTime.Now.ToString(“yyyyMMdd_HHmmss”) in order to create a dated file Name that will look like this:


string folder = Environment.SpecialFolder.MyDocuments;
string currentDate = DateTime.Now.ToString("yyyyMMdd_HHmmss");
string fileName = Path.Combine(folder, $"{currentDate}_myText.txt");


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s