Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DateTime expectedDate;
- if (!DateTime.TryParse("07/27/2012", out expectedDate))
- {
- Console.Write("Luke I am not your datetime.... NOOO!!!!!!!!!!!!!!");
- }
- string[] formats = { "MM/dd/yyyy", "M/d/yyyy", "M/dd/yyyy", "MM/d/yyyy" };
- DateTime expectedDate;
- if (!DateTime.TryParseExact("07/27/2012", formats, new CultureInfo("en-US"),
- DateTimeStyles.None, out expectedDate))
- {
- Console.Write("Thank you Mario, but the DateTime is in another format.");
- }
- private bool IsValidDateFormat(string dateFormat)
- {
- try
- {
- String dts=DateTime.Now.ToString(dateFormat);
- DateTime.ParseExact(dts, dateFormat, CultureInfo.InvariantCulture);
- return true;
- }
- catch (Exception)
- {
- return false;
- }
- }
- DateTime.ParseExact("qq", "qq", null) == DateTime.Today
- DateTime.ParseExact("myy", "501", null) == "05/01/2001"
- d,D,f,F,g,G,m,M,o,O,r,R,s,T,u,U,y,Y
- try
- {
- String formattedDate = DateTime.Now.ToString(dateFormat);
- DateTime.Parse(formattedDate);
- return true;
- }
- catch (Exception)
- {
- return false;
- }
Add Comment
Please, Sign In to add comment