Gets the date time string. - CSharp System

CSharp examples for System:DateTime Format

Description

Gets the date time string.

Demo Code


using System.Globalization;
using System;//  w  w  w . java  2s .  c o m

public class Main{
        /// <summary>
        ///     Gets the date time string.
        /// </summary>
        /// <param name="input">The input.</param>
        /// <returns></returns>
        public static string GetDateTimeString(this DateTime input)
        {
            try
            {
                var format = new CultureInfo("en-US", true);
                return input.ToString("G", format);
            }
            catch
            {
                return string.Empty;
            }
        }
}

Related Tutorials