Home > Backend Development > C#.Net Tutorial > Common codes for operating dates in ASP.NET

Common codes for operating dates in ASP.NET

怪我咯
Release: 2017-04-01 11:16:33
Original
1365 people have browsed it

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
/// Year difference from the current 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;
/// Formatted date string
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
// Formatted date string
public static string DateFormat (string date, string format) {
return DateFormat(Convert.ToDateTime(date), format);
    }

                                                                                                                    using/// Date to be formatted
/// Formatted date string
public static string DateFormat (DateTime date) {
                                                            return DateFormat(date, "yyyy-MM-dd");
///
/// Date to be formatted
">Format string
/// Formatted date string
public static string DateFormat (DateTime date, string format) {
Return date.ToString(format);
/// The date and time to be formatted
/// The formatted date and time string
public static string DateTimeFormat (DateTime datetime) {
                                                                                                                                                                                      return DateTimeFormat(datetime, "yyyy-MM-dd HH:mm"); // Format date and time
Format string
/// Formatted date and time 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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template