-6

Here is my code:

let dateStr = m.status?.match(/at (.* GMT)/)?.[1] || m.dateTimeGMT;

// Parse it safely
const dateObj = new Date(dateStr);

// Options for human-readable format
const options = {
  weekday: 'short', // Fri
  year: 'numeric', // 2001 (will be replaced)
  month: 'short', // Nov
  day: 'numeric', // 14
  hour: '2-digit',
  minute: '2-digit',
  hour12: false // 24-hour format
};

let localDate = dateObj.toLocaleString(undefined, options);

localDate = localDate.replace("2001", "2025");

console.log(localDate); // Fri, 14 Nov 2025, 14:30

I implemented cricket live streaming API on my website https://tamashaapp.com, check its home page, the date is showing 14 Nov 2001 instead of 14 Nov 2025.

What is wrong with this code so it shows the exact date format?

Note: for the time being, I use this code localDate = localDate.replace("2001", "2025"); to replace 2001 to 2025, but its not a professional way.

11
  • 3
    What is m? Please edit your question to include a minimal reproducible example. Commented Nov 13 at 20:39
  • It would probably help if you provided a locale to the [developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… Commented Nov 13 at 20:41
  • 2
    If people can't see what the value of dateStr is, it's very unlikely that anybody can help you. Commented Nov 13 at 20:47
  • 3
    @Barmar sure but my point is that we're flying blind Commented Nov 13 at 20:53
  • 5
    We shouldn't have to look at a third party website. Voting to close. Commented Nov 13 at 21:00

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.