-5

I am new to javascript. In javaScript i have to check the particular string is valid date or not. So i use Date.Parse("S.01.01.01"). But it was return the following answer (978287400000) instead of "S.01.01.01".I need to maintain this as "S.01.01.01". In C# DateTime.TryParse method can be used and this returns the proper validation for DateTime. But in javascript i have wrong result. How to solve this?

Regards, Pavithra K.

Pavi K
  • 1
  • 3
  • Pass the milliseconds into `new Date(here)`, if you want to use a resulting `Date` Object. I believe passing an invalid date might just alter the date, though, depending. Remember the Client can change JavaScript too, so you should probably take care of it on the Server. – StackSlave Jul 26 '16 at 08:59
  • Possible duplicate of [Check if a string is a date value](http://stackoverflow.com/questions/7445328/check-if-a-string-is-a-date-value) – Himanshu Tyagi Jul 26 '16 at 09:01
  • 2
    Aside from anything else, neither `Date` in Javascript nor `DateTime` in .NET maintains a format. When you parse a value, you just get the date/time as the result, with no indication of what format it was parsed in. It's really unclear what you'd *expect* to happen when you parse "S.01.01.01". – Jon Skeet Jul 26 '16 at 09:02

1 Answers1

0

Try this...

Is this you want?

var dd=Date.parse('S.01.01.01')
console.log(dd);
if (isNaN(dd)==false)
{
    var date=new Date(dd);
    console.log(date);
}
Sankar
  • 6,908
  • 2
  • 30
  • 53
  • No,this is not i want. Date.Parse() method treats "S.01.01.01" as date and return (Mon Jan 01 2001 00:00:00 GMT+0530 (India Standard Time)). My need is Date.Parse() should return "s.01.01.01" as string. – Pavi K Aug 05 '16 at 06:31
  • I'm not sure about what you are asking, But how can you think that date function(Date.parse()) return string? – Sankar Aug 05 '16 at 07:43
  • Please imagine..if i pass the invalid argument like string("ad") to Date.Parse() means what it will be return(invalid date). But when i pass "S.01.01.01" to parse() method it will treat this string as date(like jan-1-2001). I need to solve this problem. It should not take this as date. – Pavi K Aug 08 '16 at 05:32