Converting date data taken over from client to JavaScript during web development

Asked 2 years ago, Updated 2 years ago, 95 views

I need help like cider

Develop node.js, express as ejs template.

In express, render date data as ejs the variable 2016-08-14 12:03:44 of dateTime.

You want to convert the dateTime value received from ejs into a JavaScript function gapTime() that calculates how many minutes before the current time in html.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <script>
    function gapTime(time) {
       var result;
       ...
       return result
    }
    </script>
  </head>
  <body>
    <p>gapTime(<%= dateTime %>)</p>
  </body>
</html>

Of course it doesn't work like this.

Is there any way?

javascript date html node.js ejs

2022-09-22 21:15

1 Answers

It is convenient to communicate with a long value in utc format, not a formatted string, and format it when rendering on the client.

JS built-in functions are very troublesome to handle as they fly. Try the utility below.

http://momentjs.com


2022-09-22 21:15

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.