CSharp examples for System:DateTime Parse
Parse Picker Date Nullable
using System.Web; using System.Text.RegularExpressions; using System.Globalization; using System.Extensions; using System.Web.Mvc; using System.Threading.Tasks; using System.Text; using System.Linq; using System.Collections.Generic; using System.Collections; using System;//from w ww.j a v a2 s.co m public class Main{ #region DateTime Parse public static DateTime? ParsePickerDateNullable(this string input, string Format = "MM/dd/yyyy HH:mm") { if (input.IsNullOrEmpty()) return null; CultureInfo culture = CultureInfo.CurrentUICulture; var formats = new string[] { Format }; try { DateTime date; if (DateTime.TryParseExact(input, formats, CultureInfo.InvariantCulture, DateTimeStyles.None, out date)) { return date; } if (DateTime.TryParse(input, culture, DateTimeStyles.None, out date)) { return date; } } catch (Exception ex) { } return null; } /// <summary> /// Determines whether [is null or empty] [the specified s]. /// </summary> /// <param name="s">The s.</param> /// <returns></returns> public static bool IsNullOrEmpty(this string s) { if (s == null) return true; if (s.Trim() == string.Empty) return true; return false; } }