0
 fetch('http://localhost:8082/list/findbyid/'+id+'/'+productid)
          .then(response => response.json())
          .then(data => {
            const tableBody = document.getElementById('dataInven');
            data.forEach(user => {
              const row = document.createElement('tr');
              row.innerHTML = `
                <td>${user.procode}</td>
                <td>${user.proname}</td>
                <td>${user.unit}</td>
                <td>${user.cat_name}</td>
                <td>${user.quantity}</td>
                <td>${user.update_by}</td>
                <td>${user.update_date}</td>
              `;
              tableBody.appendChild(row);
            });
            
          });

this is my inner data that I query from API and after that my update_date Show Like this 2023-05-12T09:14:34.742+00:00 But want only 2023-05-15 09:14:34 am

1 Answers1

0

By using date-fns you can use .format() like:

<script type="module">
import { format } from 'https://esm.run/date-fns';
const someDate = "2023-05-12T09:14:34.742+00:00";
const dateFormatted = format(new Date(someDate), "yyyy-MM-dd hh:mm:ss a");
console.log(dateFormatted);
</script>

will output: 2023-14-12 11:14:34 AM

Roko C. Buljan
  • 196,159
  • 39
  • 305
  • 313