1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| <script> export default { data() { return { dateTime: "", yearTime: "", }; }, mounted() { this.time(); }, methods: { time() { window.setInterval(() => { const yy = new Date().getFullYear(); const mm = new Date().getMonth() + 1 < 10 ? "0" + (new Date().getMonth() + 1) : new Date().getMonth() + 1; const dd = new Date().getDate() < 10 ? "0" + new Date().getDate() : new Date().getDate(); const hh = new Date().getHours(); const mf = new Date().getMinutes() < 10 ? "0" + new Date().getMinutes() : new Date().getMinutes(); const ss = new Date().getSeconds() < 10 ? "0" + new Date().getSeconds() : new Date().getSeconds(); this.yearTime = yy + "-" + mm + "-" + dd; this.dateTime = hh + ":" + mf + ":" + ss; }, 1000); }, } }; </script>
|