Get the App
SLTechnology News&Howtos  ›  Development  › 

How does vuejs change a timestamp into a date

Shulou Source: shulou.com Published: 2022-06-03 10:13:47 10月02日 Update

This article introduces how vuejs turns the timestamp into a date. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.

Vuejs changes the timestamp into a date: 1, create the date.js file and save it to the public js folder; 2, use the "formatDate (date, 'yyyy-MM-dd hh:mm');" method in the components that need to format the timestamp.

This article operating environment: Windows7 system, vue2.9.6 version, DELL G3 computer.

How does vuejs turn a timestamp into a date?

Vue.js converts the timestamp to date format:

Export function formatDate (date, fmt) {if (/ (y +) / .test (fmt)) {fmt = fmt.replace (RegExp.$1, (date.getFullYear () +') .substr (4-RegExp.$1.length)) } let o = {'Mitchell: date.getMonth () + 1,' dwindling: date.getDate (), 'hacking: date.getHours (),' masking: date.getMinutes (), 'swarming: 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);}

Save the above code as date.js and put it in your public js folder.

Use it like this in your component that needs to format a timestamp:

{{time | formatDate}} import {formatDate} from'. / common/date.js';export default {filters: {formatDate (time) {var date = new Date (time); return formatDate (date, 'yyyy-MM-dd hh:mm');}

That's good.

About how vuejs time stamp into a date to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Time date file format content folder method more component help good code interest guy buddy article environment computer knowledge article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn OPPO Reno Docker Shulou Tech Info NVidia