Timestamp Microservice in Express.js Returning Incorrect Time

// index.js
// where your node app starts

// init project
var express = require('express');
var app = express();

// enable CORS (https://en.wikipedia.org/wiki/Cross-origin_resource_sharing)
// so that your API is remotely testable by FCC 
var cors = require('cors');
app.use(cors({optionsSuccessStatus: 200}));  // some legacy browsers choke on 204

// http://expressjs.com/en/starter/static-files.html

// http://expressjs.com/en/starter/basic-routing.html
app.get("/", function (req, res) {
  res.sendFile(__dirname + '/views/index.html');

const isInvalidDate = (date) => isNaN(date.getTime());

// your API endpoint... 
app.get("/api/:date", function (req, res) {
  let date = new Date(req.params.date);

    date = new Date(+req.params.date);
  if (isInvalidDate(date)) {
    res.json({ error: "Invalid Date" });
    unix: date.getTime(),
    utc: date.toUTCString()

// Handle empty date parameter
app.get("/api", (req, res) => {
  const currentDate = new Date(); 
    unix: currentDate.getTime(),
    utc: currentDate.toUTCString()

// Listen on port set in environment variable or default to 3000
var listener = app.listen(process.env.PORT || 3000, function () {
  console.log('Your app is listening on port ' + listener.address().port);

I’ve been working on a project in Express.js called “Timestamp Microservice” as part of my learning journey. While my code seems correct, I’m encountering an issue where the output returns the wrong time, despite the date being accurate. I’ve double-checked my implementation, including parsing the date correctly, but the time displayed doesn’t match what I expect. I’ve tried debugging by logging intermediate steps, but I’m still unable to pinpoint the source of the discrepancy. Any insights or suggestions on how to troubleshoot and resolve this issue would be greatly appreciated!

Can you give example input, the output it produces, and what your expected output is for where the time is wrong?

The code seems fine, I am just wondering if the only issue is that the Date object is giving you the time in UTC and not your local time zone. I think that’s expected, and you have to work with time zone offsets in your local system in order to display the time in your time zone. I haven’t explored any of this personally, so unfortunately I can’t give you any better insight into how to do that, but it doesn’t look like the user stories in the project on here are asking for you to accommodate timezones. Have you tried submitting the project to see if it passes the tests? If my assumption is wrong, please share more details here.

it is returning two hours behind. I also tried to submit it like that and the all the test is not passing