Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect date format defined by browser?

I'm using HTML5 input type=date field and because some browsers still don't support this feature, I would like to create error validation message for browsers that display just normal text field instead of date field. This error message should look like

Please enter date in format: ...

But I need to find the correct format, that the browser is set to. Is there any php/js/jQuery way how to find out this?

like image 744
feri baco Avatar asked May 31 '13 14:05

feri baco


People also ask

What is the date format for my browser?

The default date format for internet browsers is often set as the US date format by default. This means that in HORUS and HRMS, dates can appear as: MM/DD/YYYY.

What is the default format for date and time?

By default, the date format is MM/DD/YYYY HH24:MI:SS.US.


1 Answers

Thanks to @Jose Vega's answer I was able to find very easy way how to do it.

     var now=new Date(2013,11,31);
     var str=now.toLocaleDateString();
     str=str.replace("31","dd");
     str=str.replace("12","mm");
     str=str.replace("2013","yyyy");

Error message:

"Please enter date in format:" + str

like image 196
feri baco Avatar answered Sep 30 '22 14:09

feri baco