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);
}
}
}