Change format date using javascript from timestamp php
本问题已经有最佳答案,请猛点这里访问。
可以javascript更改从PHP采取的日期格式,如下所示:
Vue组件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | <tr v-for="(category,index) in allCategories"> <td class="v-align-middle"> <img :src="category.images[0].link" class="img-fluid categoriesImg" alt=""> </td> <td class="v-align-middle">{{category.category}}</td> <td class="v-align-middle">{{formatDate(category.created_at)}}</td> </tr> import {mapGetters} from 'vuex'; export default { name:"category", computed: { ...mapGetters({ allCategories:'allCategories' }), }, created(){ // this.$swal('Hello Vue world!!!'); this.$store.dispatch('GetAllCategories'); }, methods:{ formatDate(date){ let tanggal = new Date(date); return tanggal; }, } } |
结果
1 | "2018-09-21T22:20:48.000Z" |
您可以使用以下代码:
1 2 3 4 | var monthNames = ["January","February","March","April","May","June","July","August","September","October","November","December"]; var dayNames=['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']; d = new Date(date); time = dayNames[d.getDay()] +"," + d.getDate() + monthNames[d.getMonth()] ; |
有关更多信息,您可以在javaScript中查看日期
momentjs是最好的解决方案。
确保设置正确的格式(https://momentjs.com/docs/#/parsing/string-format/)
1 2 3 4 | formatDate(date){ let tanggal = moment(date, 'YYYY-MM-DD HH:mm:ss').format('dddd,DD MMMM'); return tanggal; }, |