Date object to string formatting
Posted on: Thu Jul 10 18:26:48 -0700 2008. Updated on: Thu Jul 10 18:27:35 -0700 2008.
Category: DotNet
Category: DotNet
To get a DateTime object as a string, or get different parts of it, you can do something like this:
DateTime date = DateTime.Now;
string dirName = String.Format("{0:yyyy}{0:MM}{0:dd}", date);
This would output: YYYYMMDD with leading zeroes.
To see a full list of formatting parameters got to: http://msdn.microsoft.com/en-us/library/8kb3ddd4(VS.71).aspx