Forum Discussion

KevinZesi's avatar
KevinZesi
Occasional Contributor
5 years ago

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