官术网_书友最值得收藏!

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:

主站蜘蛛池模板: 万全县| 东乡县| 苍南县| 中西区| 西乡县| 雅安市| 平阳县| 扶绥县| 玉山县| 林甸县| 铜川市| 梅河口市| 军事| 延津县| 邮箱| 清水河县| 新乡县| 东源县| 翁源县| 云林县| 辽宁省| 常德市| 高雄县| 浙江省| 长寿区| 红桥区| 淄博市| 墨玉县| 双辽市| 军事| 朝阳市| 邯郸市| 紫阳县| 阳原县| 开江县| 安溪县| 读书| 道孚县| 福州市| 永登县| 肥城市|