Asp. NET Operation date Common code

Source: Internet
Author: User
Tags dateformat

Using System;

Namespace My.utils {
<summary>
Date Operations Common tools
</summary>
public class Dateutils {
Public Dateutils () {
}

<summary>
Year difference of comparison date
</summary>
<param name= "Start" > Start date </param>
<returns> year difference from current date </returns>
public static int Diffyear (string start) {
Return Diffyear (Convert.todatetime (start));
}

<summary>
Year difference of comparison date
</summary>
<param name= "Start" > Start date </param>
<param name= "End" > End Date </param>
<returns> Year Difference </returns>
public static int Diffyear (string start, String end) {
Return Diffyear (Convert.todatetime (start), Convert.todatetime (end));
}

<summary>
Year difference of comparison date
</summary>
<param name= "Start" > Start date </param>
<returns> year difference from current date </returns>
public static int Diffyear (DateTime start) {
Return (Diffyear (start, DateTime.Now));
}

<summary>
Compare year differences of two dates
</summary>
<param name= "Start" > Start date </param>
<param name= "End" > End Date </param>
<returns> Year Difference </returns>
public static int Diffyear (datetime start, DateTime end) {
Return (end. Year-start. year);
}

<summary>
Format date of day (YYYY-MM-DD)
</summary>
<returns> formatted date string </returns>
public static string DateFormat () {
return DateFormat (DateTime.Now);
}

<summary>
Formatted Date (YYYY-MM-DD)
</summary>
<param name= "Date" > Date to be formatted </param>
<returns> formatted date string </returns>
public static string DateFormat (string date) {
return DateFormat (Convert.todatetime (date));
}

<summary>
Formatted date
</summary>
<param name= "Date" > Date to be formatted </param>
<param name= "format" > Formatting strings </param>
<returns> formatted date string </returns>
public static string DateFormat (string date, string format) {
return DateFormat (Convert.todatetime (date), format);
}

<summary>
Formatted Date (YYYY-MM-DD)
</summary>
<param name= "Date" > Date to be formatted </param>
<returns> formatted date string </returns>
public static string DateFormat (DateTime date) {
return DateFormat (date, "Yyyy-mm-dd");
}

<summary>
Formatted date
</summary>
<param name= "Date" > Date to be formatted </param>
<param name= "format" > Formatting strings </param>
<returns> formatted date string </returns>
public static string DateFormat (DateTime date, string format) {
Return date. ToString (format);
}

<summary>
Format Date Time
</summary>
<param name= "datetime" > Date time to be formatted </param>
<returns> Date Time string after formatting </returns>
public static string DateTimeFormat (DateTime datetime) {
Return DateTimeFormat (DateTime, "Yyyy-mm-dd hh:mm");
}

<summary>
Format Date Time
</summary>
<param name= "datetime" > Date time to be formatted </param>
<param name= "format" > Formatting strings </param>
<returns> Date Time string after formatting </returns>
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.