Advertisement
NubeColectiva

Como Mostrar la Fecha y Hora en Vue JS 3

Jun 25th, 2023
1,422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <template>
  2.   <div>
  3.     <strong>Fecha y Hora Actual: </strong>
  4.     <br>
  5.     {{ datos }}
  6.   </div>
  7. </template>
  8.  
  9. <script>
  10.  
  11.   export default {
  12.      
  13.     data() {
  14.       return {
  15.         datos: this.mostrarFechayhora()
  16.       }
  17.     },
  18.     methods:{
  19.         mostrarFechayhora: function () {
  20.  
  21.           const date = new Date();          
  22.           const formatear = ("0" + date.getDate()).slice(-2) + "-" + ("0"+(date.getMonth()+1)).slice(-2) + "-" +
  23.                             date.getFullYear() + " " + ("0" + date.getHours()).slice(-2) + ":" + ("0" + date.getMinutes()).slice(-2) + ":"
  24.                             + ("0" + date.getSeconds()).slice(-2);  
  25.           // Mostramos la fecha y hora en la consola                                  
  26.           console.log(formatear);
  27.           return formatear;
  28.      
  29.         }
  30.     },
  31.     mounted () {
  32.       this.mostrarFechayhora()
  33.     }
  34.  
  35.   }
  36.  
  37. </script>
  38.  
  39. <style scoped>
  40.   /* */
  41. </style>
Tags: vue js
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement