Asp.net time operation base class (supports short date, long date, time difference)

Source: Internet
Author: User

Copy codeThe Code is as follows: using System;
Using System. Data;
Using System. Configuration;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Web. UI. WebControls. WebParts;
Using System. Web. UI. HtmlControls;
Namespace EC
{
/// <Summary>
/// Time Operation Function
/// </Summary>
Public class TimeObject
{
/// <Summary>
/// Time Difference
/// </Summary>
/// <Param name = "starttime"> Start time </param>
/// <Param name = "endtime"> end time </param>
/// <Returns> </returns>
Public static string GetTimeSpan (DateTime starttime, DateTime endtime)
{
TimeSpan ts = endtime-starttime;
Return string. format ("{0} {1} minute {2} seconds {3} millisecond", ts. hours, ts. minutes, ts. seconds, ts. milliseconds );
}
/// <Summary>
/// Call it month-day: 09-12
/// </Summary>
/// <Param name = "d"> date </param>
/// <Returns> </returns>
Public static string ToDateMonthDay (DateTime d)
{
Return d. ToString ("MM-dd ");
}
/// <Summary>
/// Convert to year, month, and day:
/// </Summary>
/// <Param name = "d"> </param>
/// <Returns> </returns>
Public static string ToDateString (DateTime d)
{
Return d. ToString ("yyyy-MM-dd ");
}
/// <Summary>
/// Converted to: hour: minute: seconds 00:29:58
/// </Summary>
/// <Param name = "t"> </param>
/// <Returns> </returns>
Public static string ToTimeString (DateTime t)
{
Return t. ToString ("HH: mm: ss ");
}
/// <Summary>
/// Converted to long time: 00:30:57
/// </Summary>
/// <Param name = "dt"> </param>
/// <Returns> </returns>
Public static string ToDateTimeString (DateTime dt)
{
Return dt. ToString ("yyyy-MM-dd HH: mm: ss ");
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.