using System;
namespace My.Utils {
///
/// Common tools for date operations
///
public class DateUtils {
public DateUtils() {
}
summary>
static int DiffYear (string start) {
return DiffYear(Convert.ToDateTime(start));
/// & lt;/summary & gt;
/// & lt; param name = "start" & gt; start date & lt;/param & gt;
/// & lt; param name = "end" & gt; The end of the end & lt;/Param & gt;
/// & lt; RetUrns & GT; URN Diffyear (Convert.todateTime (Start ), Convert.ToDateTime(end));
}
## /// Start date
///
public static int DiffYear (DateTime start) {
using with use using ’ through using ’ ’s ’ through ’ using ’s ’ using ’s ’ using ‐ ‐ ‐ ‐‐ ‐ to
/// & lt;/summary & gt;
/// & lt; param name = "start" & gt; start date & lt;/param & gt;
/// & lt; param name = "end" & gt; The end of the end & lt;/Param & gt;
/// & lt; RetUrns & GT; # RETURN (End.year -Start. Year);
}
/// & lt; Summary & gt;
/// Format the date of the day (yyyy-mm-dd)
/// & lt;/summary & gt;
///
public static string DateFormat () {
return DateFormat(DateTime.Now);
}
; The date of formatting & lt;/param & gt;
/// & lt; Return & gt; Formatted date string & lt;/Return & GT;
Public String DateFormat (String Date) {
Return dateformat (Convert.ToDateTime(date));
}
// Date to be formatted
/// Format string
//
public static string DateFormat (string date, string format) {
return DateFormat(Convert.ToDateTime(date), format);
}
using/// Date to be formatted
///
public static string DateFormat (DateTime date) {
return DateFormat(date, "yyyy-MM-dd");
///
/// Date to be formatted
">Format string
///
public static string DateFormat (DateTime date, string format) {
Return date.ToString(format);
/// The date and time to be formatted
///
public static string DateTimeFormat (DateTime datetime) {
return DateTimeFormat(datetime, "yyyy-MM-dd HH:mm"); // Format date and time
Format string
///
Public static string DateTimeFormat (DateTime datetime, string format) {
return datetime.ToString(format);
-->
The above is the detailed content of Common codes for operating dates in ASP.NET. For more information, please follow other related articles on the PHP Chinese website!