Advertisement
NubeColectiva

Como Formatear Una Fecha y Hora en JavaScript

May 4th, 2023 (edited)
925
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const bd = "2022-08-15 21:49:44";
  2.  
  3. const date = new Date(bd);
  4.  
  5. const formatear = ("0" + date.getDate()).slice(-2) + "-" + ("0"+(date.getMonth()+1)).slice(-2) + "-" +
  6.                   date.getFullYear() + " " + ("0" + date.getHours()).slice(-2) + ":" + ("0" + date.getMinutes()).slice(-2) + ":"
  7.                   + ("0" + date.getSeconds()).slice(-2);
  8.  
  9. console.log(formatear);
  10. // 15-08-2022 21:49:44
Tags: JavaScript
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement