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

由于用了录入的时候前端用了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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容