screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <script src="https://unpkg.com/vue@3.2.12/dist/vue.global.js"></script> </head> <body> <div id="app"> <h3>Vue Js Input mask date with time</h3> <input type="text" v-model="dateTime" @input="formatDateTime" placeholder="dd/mm/yyyy hh:mm"> </div> <script type="module"> const app = Vue.createApp({ data() { return { dateTime: '' }; }, methods: { formatDateTime() { let cleanedInput = this.dateTime.replace(/\D/g, ''); if (cleanedInput.length >= 12) { const day = cleanedInput.slice(0, 2); const month = cleanedInput.slice(2, 4); const year = cleanedInput.slice(4, 8); const formattedDate = `${day}/${month}/${year}`; const hour = cleanedInput.slice(8, 10); const minute = cleanedInput.slice(10, 12); const formattedTime = `${hour}:${minute}`; this.dateTime = formattedDate + ' ' + formattedTime; } } } }); app.mount('#app'); </script> <style> #app { width: 400px; margin: 20px auto; box-shadow: 0 2px 4px 0 rgba(0, 0, 0, .24); text-align: center; padding: 20px; } input[type="text"] { padding: 5px; border: 1px solid #ccc; border-radius: 3px; width: 200px; } input[type="text"]:focus { outline: none; border-color: #007bff; } </style> </body> </html>