String As Date Time - CSharp System

CSharp examples for System:DateTime Parse

Description

String As Date Time

Demo Code


using System;/*  ww w. j  av a2  s.  co  m*/

public class Main{
        public
        static
        DateTime
        AsDateTime(
            this string str,
            DateTime defaultValue = default(DateTime))
        {
            DateTime value;

            return DateTime.TryParse(str, out value)
                        ? value
                        : defaultValue;
        }
}

Related Tutorials