GoogleCloudSamples.Services.BookDetailLookup.ParseDate C# (CSharp) Method

ParseDate() public static method

Parse a date time. Return null if it can't be parsed. A single number will be interpreted as a year, and the date returned will be YEAR-01-01.
public static ParseDate ( string dateString ) : DateTime?
dateString string A string representation of the date.
return DateTime?
        public static DateTime? ParseDate(string dateString)
        {
            DateTime result;
            if (DateTime.TryParse(dateString, out result))
                return result;
            int year;
            if (int.TryParse(dateString, out year))
                return new DateTime(year, 1, 1);
            return null;
        }