I have this code that shows some build info in an About box:
private void frmAbout_Load(object sender, EventArgs e)
{
Version versionInfo =
Assembly.GetExecutingAssembly().GetName().Version;
lblVersion.Text = String.Format("Version {0}.{1}",
versionInfo.Major.ToString(), versionInfo.Minor.ToString());
String versionStr = String.Format("{0}.{1}.{2}.{3}",
versionInfo.Major.ToString(), versionInfo.Minor.ToString(),
versionInfo.Build.ToString(), versionInfo.Revision.ToString());
lblBuild.Text = String.Format("Build {0}", versionStr);
DateTime startDate = new DateTime(2000, 1, 1); // The date from
whence the Build number is incremented (each day, not each
build; see http://stackoverflow.com/questions/27557023/how-can-
i-get-the-build-number-of-a-visual-studio-project-to-increment)
int diffDays = versionInfo.Build;
DateTime computedDate = startDate.AddDays(diffDays);
lblLastBuilt.Text += computedDate.ToLongDateString();
}
It appears like this today:
The "problem" is that screen real estate is limited, and dates such as "February 04, 2015" look geekish to me (I prefer "February 4, 2015").
I could kludgily brute-force the string returned from ToLongDateString() like so:
String lds = computedDate.ToLongDateString();
lds = // find leading 0 in date and strip it out or replace it with an empty string
lblLastBuilt += lds;
(I'm using "+=" because lblLastBuilt is set to "Last built " at design-time.
So: is there a less brute-forcish way to prevent leading 0s from appearing in the "day of month" portion of the date string?