位置: IT常识 - 正文

vue 时间格式总结及转换(vue设置时间格式)

编辑:rootadmin
vue 时间格式总结及转换

推荐整理分享vue 时间格式总结及转换(vue设置时间格式),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:vue 当前时间,vue时间戳转换日期格式,vue时间显示,vue时间显示,vue日期格式,vue时间显示,vue日期格式,vue时间显示,内容如对您有帮助,希望把文章链接给更多的朋友!

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

        一、获取当前时间。

        先看效果:

        

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

<template> <div><h1>vue 时间格式常见应用</h1><h3>获取当前时间(格式:年月日时分秒):{{time}}</h3></div></template><script>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;}}}</script>

        Ⅱ.格式:标准时间

<template> <div><h1>vue 时间格式常见应用</h1><h3>获取当前标准时间(格式:年月日时分秒):{{standard_time}}</h3></div></template><script>export default {data() {return {standard_time:''}},created() {this.getGMTtime();},methods: {getGMTtime(){this.standard_time =new Date();}}}</script>vue 时间格式总结及转换(vue设置时间格式)

        Ⅲ.格式:时间戳

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

        二、时间格式之间的转换

        效果:

        

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

<template> <h1>时间格式之间的转换</h1><h3>1.年月日时分秒格式转换成标准时间</h3><div style="display: flex;"><h5>假如将"2022-08-17 09:54:48"转换成标准时间格式,则标准格式为:</h5><h4>{{conversion_time}}</h4></div></template><script>export default {data() {return {conversion_time: new Date('2022-08-17 09:54:48')}}}</script>

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

<template> <h1>时间格式之间的转换</h1> <h3>2.标准时间转换成年月日时分秒格式</h3> <div style="display: flex;"><h5>假如将"Wed Aug 17 2022 09:54:48 GMT+0800 (中国标准时间)"转换成年月日时分秒格式,则 写为:</h5><h4>{{conversion_time1}}</h4></div></template><script>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;} }}</script>

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

<template> <h3>3.年月日时分秒格式转换成时间戳</h3> <div style="display: flex;"> <h5>假如将"2022-08-17 09:54:48"转换成时间戳,则写为:</h5><h4>{{conversion_time2}}</h4></div></template><script>export default {data() {return {conversion_time2:Date.parse('2022-08-17 09:54:48')}}}</script>

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

 那下面我们来检测一下:

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

本文链接地址:https://www.jiuchutong.com/zhishi/283656.html 转载请保留说明!

上一篇:不符合Win11硬件标准如何照样升级Win11?(不符合win11硬件要求安装会怎么样)

下一篇:IAM.exe进程能不能删除 有哪些用处(java.exe进程可以关掉吗)

  • 不含税价格计算方法
  • 增值税税额怎么算出来
  • 啥叫反倾销税
  • 去税务局开增值税专用发票需要缴费吗
  • 公司垫付生育津贴凭证
  • 转让费和押金的区别
  • 开票可以只开大数据吗
  • 不动产用于集体福利能否抵扣
  • 闲置固定资产如何做账
  • 标书的资金类型是什么
  • 贷款逾期的本金怎么计算
  • 预计负债计提时调减还是调增
  • 工程结算审核程序
  • 贴现利息应该计入哪个科目
  • 不动产评估需要明确的基本事项包括哪些内容
  • 减免税款如何申报
  • 企业所得税汇算清缴账务处理
  • 企业为员工租房后的事故处理
  • 为什么电脑上找不到蓝牙耳机
  • 资本公积 税务
  • 企业所得税汇算表
  • 路由器连接上没网络怎么回事
  • 局域网内如何设置静态ip
  • 进项税额转出如何做账分录
  • 车船税的会计分录怎么写
  • mac重装macos
  • thinkphp use命名空间
  • 其他应收款超过一年是12个月吗?
  • cuda10.1下载
  • 踩雷日记:Pytorch mmcv-full简易安装
  • 商品流通企业库存商品的核算方法主要有
  • php中get_magic_quotes_gpc()函数说明
  • 常见反爬策略
  • 减资资产负债表怎么填
  • 公司提现金用途
  • 个体工商户经济类型是内资吗
  • 城市维护建设税,教育费附加,地方教育费附加
  • 运输发票计算抵扣怎么报税
  • 增量留抵税额退还举例
  • python中删除字典里的空项目
  • 收到增值进项发票
  • 普通发票有什么
  • 负债类科目的余额方向为借方 不考虑双向等例外情况
  • 扣伙食费会计分录
  • 营业收入计入销售收入吗
  • 银行手续费没有发票要调增吗
  • 工地上购买的零食叫什么
  • 加权平均发计算公式
  • 所得税费用是指
  • 退伍军人9000补助
  • 餐饮行业采购
  • 公司两年未给员工申报个税违法吗
  • 固定资产是每月折旧吗
  • 哪些费用是不可抵扣的
  • 应付股利计提了长期不支付
  • 工程担保属于什么
  • 分享一个简单的故事英语
  • Hibernate4在MySQL5.1以上版本创建表出错 type=InnDB
  • mysql中的groupby
  • sql server 批量删除
  • sql 重复记录
  • windows xp系
  • centos7 pptp搭建
  • centos7修改网络
  • win10系统怎么设置电脑密码
  • windowsxp怎么打开设置
  • windows xp.
  • 上帝模式使用教程
  • Ubuntu12.04(X86_64)上安装Mesa-8.0.4
  • linux dig命令
  • itertools.permutations
  • unity基础包
  • The method setClass(Context, Class<?>) in the type Intent is not applicable for the问题
  • 完美世界3v3
  • 税务局上班吗今天
  • 应税消费品通过什么科目核算
  • 煤炭开什么发票
  • 立信金融会计学院
  • 电子发票冲红期限
  • 税务机关支部活动方案
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设