vue 时间格式总结及转换

您所在的位置:网站首页 怎么样将日期格式变为-年-月-日 vue 时间格式总结及转换

vue 时间格式总结及转换

2024-07-13 23:57:14| 来源: 网络整理| 查看: 265

        vue框架中我们常常用el-date-picker标签来显示和选择时间,那么,常见的时间的格式包含年-月-日(yyyy-MM-dd)、年-月-日 时-分-秒(yyyy-MM-dd HH-mm-ss)、标准时间格式以及时间戳。那么今天我们就来总结一下常用的获取方法和它们之间的转换方法。

        一、获取当前时间。

        先看效果:

        

 

          Ⅰ. 格式:年-月-日 时-分-秒(yyyy-MM-dd HH-mm-ss)

vue 时间格式常见应用 获取当前时间(格式:年月日时分秒):{{time}} export default { data() { return { time:'' } }, created() { this.getNowTime(); }, methods: { getNowTime(){ const yy = new Date().getFullYear() const MM = (new Date().getMonth() + 1) < 10 ? '0' + (new Date().getMonth() + 1) : (new Date().getMonth() + 1) const dd = new Date().getDate() < 10 ? '0' + new Date().getDate() : new Date().getDate() const HH = new Date().getHours() < 10 ? '0' + new Date().getHours() : new Date().getHours() const mm = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes() : new Date().getMinutes() const ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds() : new Date().getSeconds() this.time = yy + '-' + MM + '-' + dd + ' ' + HH + ':' + mm + ':' + ss; } } }

        Ⅱ.格式:标准时间

vue 时间格式常见应用 获取当前标准时间(格式:年月日时分秒):{{standard_time}} export default { data() { return { standard_time:'' } }, created() { this.getGMTtime(); }, methods: { getGMTtime(){ this.standard_time =new Date(); } } }

        Ⅲ.格式:时间戳

vue 时间格式常见应用 获取当前时间的时间戳:{{current_timestamp}} export default { data() { return { current_timestamp:'' } }, created() { this.getnowtimestamp(); }, methods: { getnowtimestamp(){ var date = new Date(); this.current_timestamp = Date.parse(date) } } }

        二、时间格式之间的转换

        效果:

        

        Ⅰ.年-月-日 时-分-秒格式转换成标准时间

时间格式之间的转换 1.年月日时分秒格式转换成标准时间 假如将"2022-08-17 09:54:48"转换成标准时间格式,则标准格式为: {{conversion_time}} export default { data() { return { conversion_time: new Date('2022-08-17 09:54:48') } } }

         Ⅱ.标准时间转换成年-月-日 时-分-秒格式

时间格式之间的转换 2.标准时间转换成年月日时分秒格式 假如将"Wed Aug 17 2022 09:54:48 GMT+0800 (中国标准时间)"转换成年月日时分秒格式,则 写为: {{conversion_time1}} export default { data() { return { conversion_time1:'', } }, created() { this.gettime(); }, methods: { gettime(){ var date = new Date('Wed Aug 17 2022 09:54:48 GMT+0800 (中国标准时间)'); var y = date.getFullYear(); var m = date.getMonth() + 1; m = m < 10 ? ('0' + m) : m; var d = date.getDate(); d = d < 10 ? ('0' + d) : d; var h = date.getHours(); h = h < 10 ? ('0' + h) : h; var min = date.getMinutes(); min = min < 10 ? ('0' + min) : min; var s = date.getSeconds(); s = s < 10 ? ('0' + s) : s; this.conversion_time1 = y + '-' + m + '-' + d + ' ' + h + ':' + min + ':' + s; } } }

        Ⅲ.年-月-日 时-分-秒格式转换成时间戳

3.年月日时分秒格式转换成时间戳 假如将"2022-08-17 09:54:48"转换成时间戳,则写为: {{conversion_time2}} export default { data() { return { conversion_time2:Date.parse('2022-08-17 09:54:48') } } }

这时你是不是有点困惑怎么来判断转换的时间戳是否正确呢,我们可以通过在线的转换工具来转换检测,转换工具网址:时间戳(Unix timestamp)转换工具 - 在线工具

 那下面我们来检测一下:

 所以转换的是没有问题的!



【本文地址】

公司简介

联系我们

今日新闻


点击排行

实验室常用的仪器、试剂和
说到实验室常用到的东西,主要就分为仪器、试剂和耗
不用再找了,全球10大实验
01、赛默飞世尔科技(热电)Thermo Fisher Scientif
三代水柜的量产巅峰T-72坦
作者:寞寒最近,西边闹腾挺大,本来小寞以为忙完这
通风柜跟实验室通风系统有
说到通风柜跟实验室通风,不少人都纠结二者到底是不
集消毒杀菌、烘干收纳为一
厨房是家里细菌较多的地方,潮湿的环境、没有完全密
实验室设备之全钢实验台如
全钢实验台是实验室家具中较为重要的家具之一,很多

推荐新闻


图片新闻

实验室药品柜的特性有哪些
实验室药品柜是实验室家具的重要组成部分之一,主要
小学科学实验中有哪些教学
计算机 计算器 一般 打孔器 打气筒 仪器车 显微镜
实验室各种仪器原理动图讲
1.紫外分光光谱UV分析原理:吸收紫外光能量,引起分
高中化学常见仪器及实验装
1、可加热仪器:2、计量仪器:(1)仪器A的名称:量
微生物操作主要设备和器具
今天盘点一下微生物操作主要设备和器具,别嫌我啰嗦
浅谈通风柜使用基本常识
 众所周知,通风柜功能中最主要的就是排气功能。在

专题文章

    CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭