Return a elapsed time in formatted string. (hh:mm:ss:mi)
// crudwork
// Copyright 2004 by Steve T. Pham (http://www.crudwork.com)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with This program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Collections.Generic;
using System.Text;
namespace crudwork.Utilities
{
/// <summary>
/// Date Utility
/// </summary>
public class DateUtil
{
/// <summary>
/// return a elapsed time in formatted string. (hh:mm:ss:mi)
/// </summary>
/// <param name="ticks"></param>
/// <returns></returns>
public static string ElapsedTime(long ticks)
{
TimeSpan ts = new TimeSpan(ticks);
return String.Format("{0}:{1}:{2}:{3}",
ts.Hours,
ts.Minutes,
ts.Seconds,
ts.Milliseconds
);
}
/// <summary>
/// return a elapsed time in formatted string. (hh:mm:ss:mi)
/// </summary>
/// <param name="t1"></param>
/// <returns></returns>
public static string ElapsedTime(DateTime t1)
{
return ElapsedTime(t1, DateTime.Now);
}
/// <summary>
/// return a elapsed time in formatted string. (hh:mm:ss:mi)
/// </summary>
/// <param name="t1"></param>
/// <param name="t2"></param>
/// <returns></returns>
public static string ElapsedTime(DateTime t1, DateTime t2)
{
if (t2 > t1)
return ElapsedTime(t2.Ticks - t1.Ticks);
else
return ElapsedTime(t1.Ticks - t2.Ticks);
}
}
}
Related examples in the same category