2010-04-09 22 views

Antwort

17

Check-out Date.parse

str = "09-Apr-2010" 
date = new Date(Date.parse(str.replace(/-/g, " "))) 
alert(date.toLocaleString()) 
+0

Es works.Thanks – Dee

+0

Eine Einschränkung: Date.parse mit ISO-Format Daten ("2010-04-01") scheint nicht auf IE7 zu funktionieren, obwohl es in Firefox und Chrome funktioniert. –

1

Versuchen Sie, diese Arbeit sollte

<script language="javascript"> 
    function validateDate(oSrc, args) 
    { 
     var iDay, iMonth, iYear; 
     var arrValues; 
     arrValues = args.Value.split("/"); 
     iMonth = arrValues[0]; 
     iDay = arrValues[1]; 
     iYear = arrValues[2]; 

     var testDate = new Date(iYear, iMonth - 1, iDay); 

     if ((testDate.getDate() != iDay) || 
      (testDate.getMonth() != iMonth - 1) || 
      (testDate.getFullYear() != iYear)) 
     { 
      args.IsValid = false; 
      return; 
     } 

     return true; 
    } 
</script> 
+0

@Eonasdan Danke. – Ravia

+0

np. Ich weiß, dass es alt ist, aber ich bin über Google hierher gekommen, also dachte ich mir, dass noch andere kommen könnten :) – Eonasdan