JavaScript

把字符串格式的时间按自定义格式显示出来

2017-12-08  本文已影响56人  Lia代码猪崽

由于用了录入的时候前端用了elmentUI的日期时间选择器,传给后台的是一个date格式的字符串,所以当获取的时候,后台传回来也是这样子。

要显示的话,会出现东八区什么啊,不直观,所以需要再格式化。
以下场景是在表格里(其余的省略了):

<el-table-column label="提醒时间" width="380">
       <!--很遗憾,由于不直观,需要处理,所以下行注释了-->
       <!--<el-table-column prop="dueDate" label="提醒时间" width="380">-->
       <template scope="props">
           <div v-if="props.row.dueDate">
                {{ new Date(props.row.dueDate).getFullYear()}}年
                <!--月份就是那么特别,一定要加1-->
                {{ (new Date(props.row.dueDate).getMonth() + 1)}}月
                {{ new Date(props.row.dueDate).getDate()}}日
                {{ new Date(props.row.dueDate).getHours()}}时
                {{ new Date(props.row.dueDate).getMinutes()}}分
           </div>
       </template>
</el-table-column>

其实就是获取到字符串后,先转cheng

上一篇 下一篇

猜你喜欢

热点阅读