20081218

Simplify Simplify Simplify

Here is the code as found ::
private string FormatTime(object DateTimeValue)
{
string result = " ";
if (DateTimeValue != null)
{
DateTime dt = DateTime.Parse(DateTimeValue.ToString());
if (dt.Hour < 10)
result = FILLER_NUMBER + dt.Hour.ToString() + ":";
else
result = dt.Hour.ToString() + ":";

if (dt.Minute < 10)
result += (FILLER_NUMBER + dt.Minute.ToString() + ":");
else
result += (dt.Minute.ToString() + ":");

if (dt.Second < 10)
result += (FILLER_NUMBER + dt.Second.ToString());
else
result += dt.Second.ToString();
}

return result;
}


Here is the refactored version::

return DateTime.Parse(DateTimeValue.ToString()).ToString("HH:mm:ss");

No comments:

Post a Comment

Be nice... it's the only internet we have.

License & copyright

Creative Commons License
StinkySQL weblog and any related pages, including the weblog's archives are licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.