1

We have a requirement that the user will give the Date format in the text field, we have to validate the date format whether it is valid or not based on the Salesforce Localization method.

But SF localization method is not understanding a few of the valid formats like DD/MM/YYYY and giving output as Invalid Date.

Eg:

$A.localizationService.formatDate(new Date(), 'DD/MM/YYYY') ;
    output: "31/12/2019"
$A.localizationService.formatDate('31/12/2019', 'DD/MM/YYYY') ;
    **final output: "Invalid Date"**

Is there a way in JS to find whether the date is valid or not. We tried Date.parse but it also gives NaN (Date.parse('30/12/2019'))

2
  • are you using date picker to input the date? Jan 2, 2020 at 8:26
  • No, just text field @r
    – imran md
    Jan 2, 2020 at 8:48

1 Answer 1

1

As per documentation localizationService supports only ISO 8601.

The date parameter can be a String, Number, or most typically a JavaScript Date. If you provide a String value, use ISO 8601 format to avoid parsing warnings.

31/12/2019 is not as per ISO 8601 format.

You either need to convert that to the supported format or a valid Date object in JS.

JavaScript Date Objects

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .