I need help checking the date string of a date in Javascript based on browser language.
I can get the datetime format quite easily, for example, if the language is set to pt-BR, the format will be
dd/MM/yyyy HH:mm:ss
I tried using something like this:
var dateFormat = "dd/MM/yyyy HH:mm:ss"; var x = Date.parseExact($("#theDate").val(), dateFormat);
However, x is always Null. I think because Date.parseExact cannot do times. I need to do this for all browser languages, and I would prefer not to use another library. There is no use of Regex, since I need to write so many different expressions.
Does anyone have any suggestions to help me find the right path? I also do not mind using the web method.
I tried using the following web method that works with en-US, but nothing more:
Public Function ValidateDates(ByVal strDate_In As String) As String Dim theFormat As String = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern() + " " + CultureInfo.CurrentCulture.DateTimeFormat.LongTimePattern() Try Dim d As DateTime = DateTime.ParseExact(strDate_In, theFormat, CultureInfo.CurrentCulture) Return "true" Catch ex As Exception Return "false" End Try End Function
Nititerip
source share