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%
Quick Start 1. Find the nginx image on Docker Hub...
Recently, the company has put forward a requireme...
Table of contents 1. Brief Overview 2. JSON basic...
Enable remote access rights for mysql By default,...
You can add comments to MySQL SQL statements. Her...
System environment: Windows 7 1. Install Docker D...
In MySQL, we often use order by for sorting and l...
I don’t know why, but UI likes to design honeycom...
When I surf the Net, I often see web sites filled...
1. Prerequisites Since I have installed it severa...
A cool JavaScript code to unfollow Weibo users in...
Table of contents 1. Installation 2. Import 3. De...
Regarding the high availability solutions for Ora...
Map tags must appear in pairs, i.e. <map> .....
Table of contents 1. Understanding the Equality R...