Skip to content

Instantly share code, notes, and snippets.

@nickmartini
Created August 20, 2009 16:32
Show Gist options
  • Save nickmartini/171176 to your computer and use it in GitHub Desktop.
Save nickmartini/171176 to your computer and use it in GitHub Desktop.
public static string BuildDateDirectory()
{
string year = DateTime.Now.Year.ToString();
string month = DateTime.Now.Month.ToString();
string day = DateTime.Now.Day.ToString();
string hour = DateTime.Now.Hour.ToString();
string minute = DateTime.Now.Minute.ToString();
if (month.Length == 1)
month = string.Format("0{0}", month);
if (day.Length == 1)
day = string.Format("0{0}", day);
if (hour.Length == 1)
hour = string.Format("0{0}", hour);
if (minute.Length == 1)
minute = string.Format("0{0}", minute);
return string.Format("{0}-{1}-{2} {3}{4}", year, month, day, hour, minute);
}
VERSUS
DateTime.Now.ToString("yyyy-MM-dd HHmm");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment