Using system;
Namespace my. utils {
/// <Summary>
/// Common tools for date operations
/// </Summary>
Public class dateutils {
Public dateutils (){
}
/// <Summary>
/// Compare the year difference of the date
/// </Summary>
/// <Param name = "start"> Start date </param>
/// <Returns> year difference from the current date </returns>
Public static int diffyear (string start ){
Return diffyear (convert. todatetime (start ));
}
/// <Summary>
/// Compare the year difference of the 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>
/// Compare the year difference of the date
/// </Summary>
/// <Param name = "start"> Start date </param>
/// <Returns> year difference from the current date </returns>
Public static int diffyear (datetime start ){
Return (diffyear (START, datetime. Now ));
}
/// <Summary>
/// Compare the year difference between 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 the date of the current day (yyyy-mm-dd)
/// </Summary>
/// <Returns> formatted date string </returns>
Public static string dateformat (){
Return dateformat (datetime. Now );
}
/// <Summary>
/// Format the 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>
/// Format the date
/// </Summary>
/// <Param name = "date"> date to be formatted </param>
/// <Param name = "format"> Format String </param>
/// <Returns> formatted date string </returns>
Public static string dateformat (string date, string format ){
Return dateformat (convert. todatetime (date), format );
}
/// <Summary>
/// Format the 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>
/// Format the date
/// </Summary>
/// <Param name = "date"> date to be formatted </param>
/// <Param name = "format"> Format String </param>
/// <Returns> formatted date string </returns>
Public static string dateformat (datetime date, string format ){
Return date. tostring (format );
}
/// <Summary>
/// Format the date and time
/// </Summary>
/// <Param name = "datetime"> date and time to be formatted </param>
/// <Returns> formatted Date and Time string </returns>
Public static string datetimeformat (datetime ){
Return datetimeformat (datetime, "yyyy-mm-dd hh: mm ");
}
/// <Summary>
/// Format the date and time
/// </Summary>
/// <Param name = "datetime"> date and time to be formatted </param>
/// <Param name = "format"> Format String </param>
/// <Returns> formatted Date and Time string </returns>
Public static string datetimeformat (datetime, string format ){
Return datetime. tostring (format );
}
}
}