Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does vuejs change a timestamp into a date

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report