Open AndrewASel opened 4 days ago
That's strange. Can you check if you have some additional settings in k6 that could affect the date formatting? I'm unable to reproduce it using a common setup:
and this is for debugging:
Current date: Fri Nov 01 2024 10:08:05 GMT+0300 (GMT+03:00)
could you share a project to reproduce?
Hello @mbolotov It definitely strange, I checked JS docs, new Date() should return format like Fri Nov 01 2024 10:08:05 GMT+0300 (GMT+03:00) https://www.w3schools.com/js/js_dates.asp
But looks like in K6 it works differently, I just created simple test in grafana test builder, only added console log for a date.
It also returns this formatted date: 2024-11-01T21:01:23.742Z
Run it locally and format the same
Maybe it related with date format settings, I checked on windows and ubuntu This is a simple test:
import { sleep } from 'k6'
import http from 'k6/http'
export const options = {
stages: [
{ duration: '1m', target: 1 }
],
}
export default function main() {
let date = new Date();
console.log(date);
sleep(10)
}
I not sure, probably this docs are related with it https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#date_time_string_format https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date-time-string-format
21.4.1.32 Date Time String Format ECMAScript defines a string interchange format for date-times based upon a simplification of the ISO 8601 calendar date extended format. The format is as follows: YYYY-MM-DDTHH:mm:ss.sssZ
Okay, I got it.
The k6 itself and the debugger (Node.js) behave the same in fact.
If you pass a date directly to console.log
, it will be formatted using the ISO 8601.
if you concatenate a date with other string, the runtime will call Date.toString()
function which returns a string in the format Thu Jan 01 1970 00:00:00 GMT+0000 (Coordinated Universal Time)
So this code prints the same for both run
and debug
:
export default function () {
let a= new Date()
console.log(a)
console.log("" + a)
}
When you look at a date object in debug evaluation view, it obviously format a date using toString()
function:
During run test
new Date()
returns 2024-10-31T22:42:19.356ZDuring debug test
new Date()
returns: Thu Oct 31 2024 18:42:19 GMT-0400 (Eastern Daylight Time)