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 vuejs converts milliseconds to dates

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

Share

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

What this article shares with you is about how vuejs converts milliseconds into dates. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

Vuejs converts milliseconds into dates: 1, define the filter "filters.js"; 2, introduce "filters.js" where used; 3, convert through "formatDate (data,'yyyy-MM-dd');".

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

How does vuejs convert milliseconds to dates?

Vue converts milliseconds to an instance of normal date format

Filter-timestamp conversion

Step 1: define the filter, filters.js

Export function formatDate (date, fmt) {if (/ (y +) / .test (fmt)) {fmt = fmt.replace (RegExp.$1, (date.getFullYear () +'). Substr (4-RegExp.$1.length));} let o = {'date.getFullYear (): date.getMonth () + 1,' dystopia: date.getDate (), 'hype: date.getHours (),' masks: date.getMinutes (), 'clients: 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);}

Step 2: introduce filters.js where it is used

Import {formatDate} from'.. /.. / common/filters.js'

Step 3: use the

Filters: {formatDate (time) {var data = new Date (time); return formatDate (data,'yyyy-MM-dd');}}

{{item.rateTime | formatDate}} above is how vuejs converts milliseconds into dates. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

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