Vue converts a timestamp to a custom time format.
1. First create a date. js file and write the following code:
Export function formatDate (date, fmt) {if (/(y + )/. test (fmt) {fmt = fmt. replace (RegExp. $1, (date. getFullYear () + ''). substr (4-RegExp. $1. length);} let o = {'m + ': date. getMonth () + 1, 'D + ': date. getDate (), 'H + ': date. getHours (),'m + ': date. getMinutes (),'s + ': date. getSeconds ()}; for (let k in o) {if (new RegExp ('($ {k })'). test (fmt) {let str = o [k] + ''; fmt = fmt. replace (RegExp. $1, (RegExp. $1. length = 1 )? Str: padLeftZero (str) ;}return fmt ;}; function padLeftZero (str) {return ('00' + str). substr (str. length );};
2. Introduce the date. js file on the page to be converted:
Import {formatDate} from '../date. js ';
3. The call method is as follows:
FormatDate (new Date (time * 1000), 'yyyy-MM-dd hh: mm ');
The preceding vue's method of converting the timestamp into a custom time format is to share all the content with you. I hope you can give us a reference, and hope you can also provide more support for the customer's house.