Convert date format to JP using locale information

I need to create a date format in the UK using the date format and language in the USA as "en_GB" in JavaScript. The problem is that my user interface returns the date selected by the user in the format of the current user language, and I want to compare it with another date that comes from an application that always gives me only one format [MM/DD/YY]

Now in JavaScript on the page, I was able to skip these two dates, but since the format is different, the comparison fails.

 if(Date.parse(selReqDate) < Date.parse(curDate)) 

The inputs that I have are:

 locale : en_GB uk locale selecteddate : 01/08/2005 [DD/MM/YY] us locale currentdate : 08/01/2005 [MM/DD/YY] 

I have the same problem with all locales except US.

+4
source share
1 answer

use toLocaleDateString

 var date = new Date(Date.UTC(2012, 11, 11, 3, 0, 0)); date.toLocaleDateString('en-GB'); // "11/12/2012" date.toLocaleDateString('en-US'); // "12/11/2012" 
+1
source

Source: https://habr.com/ru/post/1491787/


All Articles