- 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:

- Getting Started with Citrix XenApp? 7.6
- Mastering Entity Framework Core 2.0
- Boost C++ Application Development Cookbook(Second Edition)
- 精通Scrapy網(wǎng)絡(luò)爬蟲
- Android Native Development Kit Cookbook
- 從0到1:Python數(shù)據(jù)分析
- 微信小程序入門指南
- Learning FuelPHP for Effective PHP Development
- Java EE 8 Application Development
- JavaScript腳本特效編程給力起飛
- Clean Code in C#
- 遠(yuǎn)方:兩位持續(xù)創(chuàng)業(yè)者的點(diǎn)滴思考
- 從零開始:C語言快速入門教程
- 和孩子一起學(xué)編程:用Scratch玩Minecraft我的世界
- Java核心技術(shù)速學(xué)版(第3版)