When vue2 converts timestamps, it generally uses filters. After vue3, vue3 removes filters and can no longer be used. The official recommendation is to use methods or calculated properties. A Time.ts file is written below, which can convert timestamps: class Time { //Format time public formatTime(time: number) { let date = new Date(time * 1000); let year = date.getFullYear(); let month = date.getMonth() + 1; let day = date.getDate(); let hour = date.getHours(); let minute = date.getMinutes(); let second = date.getSeconds(); return year + "-" + month.toString().padStart(2, "0") + "-" + day.toString().padStart(2, "0") + " " + hour.toString().padStart(2, "0") + ":" + minute.toString().padStart(2, "0") + ":" + second.toString().padStart(2, "0"); } } const time = new Time(); export default time; To use it, just call this method in the template and pass in the corresponding timestamp. {{ time.formatTime(timestamp) }} Display effect:
Currently, it can only be converted into the above format. If more formats are required, you can add a second parameter to This is the end of this article about vue3 timestamp conversion (without using filters). For more relevant vue3 timestamp conversion content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Problem of retrieving root password in MYSQL 5.7 under Linux (tested and available)
>>: 14 practical experiences on reducing SCSS style code by 50%
Without further ado Start recording docker pullin...
Quickly modify the table structure of a MySQL tab...
Effect Preview Press the "Click to Preview&q...
The establishment of MySQL index is very importan...
I. Overview When writing HTML templates, spaces a...
Table of contents Brief Analysis of MySQL Master-...
question Recently I encountered a requirement to ...
Most websites nowadays have long pages, some are ...
Install FFmpeg flac eric@ray:~$ sudo apt install ...
First download VMware Workstation 15.1 version. I...
Add multiple lines to the specified file in Docke...
Set Tomcat to automatically start the service: I ...
The file server is one of the most commonly used ...
1. Color matching effect preview As shown in the ...
1.MySQL UPDATE JOIN syntax In MySQL, you can use ...