Get Date - CSharp System

CSharp examples for System:DateTime Calculate

Description

Get Date

Demo Code


using System.Globalization;
using System.Text.RegularExpressions;
using System.Web;
using System.Linq;
using System.Collections.Generic;
using System;/* w w w . ja  v  a  2 s .com*/

public class Main{
            public static string GetDate(string datetimestr, string replacestr)
            {
                if (datetimestr == null) return replacestr;
                if (datetimestr.Equals("")) return replacestr;
                try
                {
                    datetimestr = Convert.ToDateTime(datetimestr).ToString("yyyy-MM-dd").Replace("1900-01-01", replacestr);
                }
                catch
                {
                    return replacestr;
                }
                return datetimestr;
            }
            public static string GetDate()
            {
                return DateTime.Now.ToString("yyyy-MM-dd");
            }
}

Related Tutorials