CSharp examples for System:DateTime Parse
Parse Picker Date
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;// w w w .jav a 2s. com public class Main{ public static DateTime ParsePickerDate(this string input, string Format = "MM/dd/yyyy HH:mm") { if (input.IsNullOrEmpty()) return default(DateTime); CultureInfo culture = CultureInfo.CurrentUICulture; var formats = new string[] { Format }; //new[] { //"u", //"s", //"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'", //"yyyy-MM-ddTHH:mm:ssZ", //"yyyy-MM-dd HH:mm:ssZ", //"yyyy-MM-ddTHH:mm:ss", //"yyyy-MM-ddTHH:mm:sszzzzzz", //"M/d/yyyy h:mm:ss tt" // default format for invariant culture //}; 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) { } return default(DateTime); } /// <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; } }