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

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:

主站蜘蛛池模板: 合阳县| 射阳县| 洛川县| 阳春市| 牡丹江市| 墨竹工卡县| 平江县| 麻栗坡县| 通河县| 宁南县| 沁水县| 富源县| 江源县| 丹江口市| 昌都县| 延川县| 巴青县| 民勤县| 花莲市| 闻喜县| 阿鲁科尔沁旗| 郧西县| 兴文县| 什邡市| 南溪县| 宜城市| 当涂县| 西华县| 攀枝花市| 东山县| 唐河县| 鞍山市| 平陆县| 昭苏县| 盐山县| 安宁市| 江永县| 清河县| 西畴县| 南汇区| 兴仁县|