Asp. NET date Operations common operation code

Source: Internet
Author: User
Tags date comparison dateformat datetime string format

Using System;





namespace My.utils {


///


///Date Operations common tools


///


public class Dateutils {


public dateutils () {


 }





    ///


///The year difference of the comparison date


    ///


    ///


Start Date


    ///


the year difference with the current date


public static int Diffyear (string start) {


return Diffyear (Convert.todatetime (start));


    }





    ///


///The year difference of the comparison date


    ///


    ///


Start Date


    ///


End Date


    ///


Year Difference


public static int Diffyear (string start, String end) {


return Diffyear (Convert.todatetime (start), Convert.todatetime (end));


    }





///


///The year difference of the comparison date


    ///


    ///


Start Date


    ///


the year difference with the current date


public static int diffyear (DateTime start) {


return (Diffyear (start, DateTime.Now));


    }





    ///


///compares the year difference of two dates


    ///


    ///


Start Date


    ///


End Date


    ///


Year Difference


public static int Diffyear (datetime start, DateTime end) {


return (end. Year-start. year);


    }





    ///


///Format Day date (YYYY-MM-DD)


    ///


    ///


the formatted date string


public static string DateFormat () {


return DateFormat (DateTime.Now);


    }





///


///Format Date (YYYY-MM-DD)


    ///


    ///


date to be formatted


    ///


the formatted date string


public static string DateFormat (string date) {


return DateFormat (convert.todatetime (date));


    }





    ///


///Format Date


    ///


    ///


date to be formatted


    ///


format string


    ///


the formatted date string


public static string DateFormat (string date, string format) {


return DateFormat (convert.todatetime (date), format);


    }





    ///


///Format Date (YYYY-MM-DD)


    ///


    ///


date to be formatted


    ///


the formatted date string


public static string DateFormat (DateTime date) {


return DateFormat (date, "Yyyy-mm-dd");


    }





    ///


///Format Date


    ///


    ///


date to be formatted


    ///


format string


    ///


the formatted date string


public static string DateFormat (DateTime date, string format) {


return date. ToString (format);


    }





    ///


///Format Date Time


    ///


    ///


date time to be formatted


    ///


formatted date-time string


public static string DateTimeFormat (DateTime datetime) {


return DateTimeFormat (datetime, "Yyyy-mm-dd hh:mm");


    }





    ///


///Format Date Time


    ///


///


date time to be formatted


    ///


format string


    ///


formatted date-time string


public static string DateTimeFormat (DateTime datetime, string format) {


return DateTime. ToString (format);


    }


}


}

Related Article

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.