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:
odjbin
2022-12-26 14:20:23 +00:00
3 changed files with 25 additions and 3 deletions

View File

@@ -9,7 +9,7 @@
</view> </view>
<view style="display: flex;"> <view style="display: flex;">
<text class="xw_time"> <text class="xw_time">
{{item.pub_time}} {{item.pub_time_str}}
</text> </text>
<text class="xw_time xw_place"> <text class="xw_time xw_place">
{{item.pub_name}} {{item.pub_name}}
@@ -21,6 +21,9 @@
</template> </template>
<script> <script>
import {
dateFormat
} from '../../utills/date.js'
export default { export default {
data() { data() {
return { return {
@@ -52,7 +55,10 @@
// } // }
getNews() { getNews() {
this.$apiServe.getNews().then(res => { 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 this.newsList = res.data.data
}).finally(_ => {}) }).finally(_ => {})
}, },

View File

@@ -24,7 +24,7 @@
:lazy-load="true"> :lazy-load="true">
</u-image> </u-image>
<text class="release">发布日期</text> <text class="release">发布日期</text>
<text>{{item.pub_time}}</text> <text>{{item.pub_time_str}}</text>
</view> </view>
</view> </view>
</view> </view>

16
utills/date.js Normal file
View 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
}