Cannot figure out Timestamp Microservice project

I am trying to figure out how to handle dates that can be successfully parsed by
new Date(date_string). I need to figure this out to complete my project. Can someone guide or explain how this could be done

Please refer to the following code:

let resObject = {}

app.get("/api/:input", function (req, res) {
  let input = req.params.input

  if(input.includes('-')) {
    /*Date String*/
    resObject['unix'] = new Date(input).getTime()
    resObject['utc'] = new Date(input).toUTCString()
  } else {

    input = parseInt(input)

    resObject['unix'] = new Date(input).getTime()
    resObject['utc'] = new Date(input).toUTCString() 

   // date.setHours(date.getHours() + 9)  
  }
    if(!resObject['unix'] || !resObject['utc']){
      res.json({ error: "Invalid Date" })
    }

  res.json(resObject);
});

app.get("/api", function (req, res) {
  resObject['unix'] = new Date().getTime()
  resObject['utc'] = new Date().toUTCString()

  res.json(resObject);
});

Hello there,

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

1 Like