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