Merge pull request 'dengjie commit : 发布日期格式解决' (#35) from DJ into dev
Reviewed-on: http://git.hchyun.com/feashow/pupil/pulls/35
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
</view>
|
||||
<view style="display: flex;">
|
||||
<text class="xw_time">
|
||||
{{item.pub_time}}
|
||||
{{item.pub_time_str}}
|
||||
</text>
|
||||
<text class="xw_time xw_place">
|
||||
{{item.pub_name}}
|
||||
@@ -21,6 +21,9 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {
|
||||
dateFormat
|
||||
} from '../../utills/date.js'
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
@@ -52,7 +55,10 @@
|
||||
// }
|
||||
getNews() {
|
||||
this.$apiServe.getNews().then(res => {
|
||||
// console.log('行业新闻', res.data.data)
|
||||
console.log('行业新闻', res.data.data)
|
||||
for (const item of res.data.data) {
|
||||
item.pub_time_str = dateFormat(item.pub_time_str)
|
||||
}
|
||||
this.newsList = res.data.data
|
||||
}).finally(_ => {})
|
||||
},
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
:lazy-load="true">
|
||||
</u-image>
|
||||
<text class="release">发布日期:</text>
|
||||
<text>{{item.pub_time}}</text>
|
||||
<text>{{item.pub_time_str}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
16
utills/date.js
Normal file
16
utills/date.js
Normal file
@@ -0,0 +1,16 @@
|
||||
function dateFormat(time) {
|
||||
let date = new Date(time);
|
||||
let year = date.getFullYear();
|
||||
// 在日期格式中,月份是从0开始的,因此要加0,使用三元表达式在小于10的前面加0,以达到格式统一 如 09:11:05
|
||||
let month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
|
||||
let day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
|
||||
let hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
|
||||
let minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
|
||||
let seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
|
||||
// 拼接
|
||||
return year + "-" + month + "-" + day + " " + hours + ":" + minutes;
|
||||
// return year + "-" + month + "-" + day;
|
||||
}
|
||||
module.exports = {
|
||||
dateFormat
|
||||
}
|
||||
Reference in New Issue
Block a user