// Display Millisecond component with full date and time.
outputBlock.Text += String.Format("Date and Time with Milliseconds: {0}",
dateValue.ToString("MM/dd/yyyy hh:mm:ss.fff tt")) + "\n";
outputBlock.Text += String.Format("Date and Time with Milliseconds: {0}",
dateOffsetValue.ToString("MM/dd/yyyy hh:mm:ss.fff tt")) + "\n";
// Append millisecond pattern to current culture's full date time pattern
string fullPattern = DateTimeFormatInfo.CurrentInfo.FullDateTimePattern;
fullPattern = Regex.Replace(fullPattern, "(:ss|:s)", "$1.fff");
// Display Millisecond component with modified full date and time pattern.
outputBlock.Text += String.Format("Modified full date time pattern: {0}",
dateValue.ToString(fullPattern)) + "\n";
outputBlock.Text += String.Format("Modified full date time pattern: {0}",
dateOffsetValue.ToString(fullPattern)) + "\n";
}
catch (FormatException)
{
outputBlock.Text += String.Format("Unable to convert {0} to a date.", dateString) + "\n";
}
}
}