Date.toLocaleString not working
Hello there,
I have a question regarding the Date object in JavaScript.
I want to use the following:
function myFunction()
{
...
var myDate = new Date(year, month-1, day);
var options = { year: 'numeric', month: '2-digit', day: '2-digit' };
Log.Message("myDate...", "myDate is: " + myDate.toLocaleString('de-DE', options));
// expected: 02.06.2020
// result: Mon Jun 02 2020 00:00:00 GMT+0200 (Mitteleuropäische Sommerzeit)
}
as you can see in my test log message I get a different result.
does TestComplete not support this method or am I using it wrong?
the ECMAScript specification of the Date object is this: https://www.ecma-international.org/ecma-262/6.0/#sec-date-objects
and TestComplete uses ECMAScript 6 for JavaScript, as it is stated here: https://support.smartbear.com/viewarticle/77297/
so I thought I can use this method of Date.
any suggestions? help?
thanks in advance,
Kevin
The problem with .toLocaleString not working as documented in JavaScript documentation should be raised as a support issue directly with SmartBear. I reproduced the problem and, you are correct, counter to JavaScript documentation, the method is not operating as expected.
In the meantime, consider using https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqconvert/datetimetoformatstr.html to create your own formatting if there's a particular formatting you want for dates.