- Vue.js 2.x by Example
- Mike Street
- 194字
- 2021-07-02 20:00:27
Format registered date
The registered date field in the data is computer friendly, which is not very human-friendly to read. Create a new method titled formatDate that takes one parameter — similar to the formatBalance method previously.
If you want full customization of the display of your date, there are several libraries available, such as moment.js, that give you much more flexibility over the output of any date and time-based data. For this method, we are going to use a native JavaScript function, to LocaleString():
formatDate(date) {
let registered = new Date(date);
return registered.toLocaleString('en-US');
}
With the registered date, we pass it to the native Date() function so JavaScript knows to interpret the string as a date. Once stored in the registered variable, we return the object as a string with the toLocaleString() function. This function accepts a huge array of options (as outlined on MDN) to customize the output of your date. For now, we'll pass it the locale we wish to display and use the defaults for that location. We can now utilize our method in the view:
<td>{{ formatDate(person.registered) }}</td>
Each table row should now look like the following:

- 程序員面試筆試寶典(第3版)
- C語言程序設(shè)計實訓(xùn)教程
- 用Flutter極速構(gòu)建原生應(yīng)用
- Java系統(tǒng)化項目開發(fā)教程
- 微信小程序全棧開發(fā)技術(shù)與實戰(zhàn)(微課版)
- 軟件測試實用教程
- Getting Started with Polymer
- 并行編程方法與優(yōu)化實踐
- ASP.NET Web API Security Essentials
- 會當(dāng)凌絕頂:Java開發(fā)修行實錄
- C語言程序設(shè)計教程
- Less Web Development Cookbook
- Go Systems Programming
- 讓Python遇上Office:從編程入門到自動化辦公實踐
- Scratch少兒編程高手的7個好習(xí)慣