在vue项目中显示实时时间(年月日时分秒)
1.在data中定义一个变量,存储时间
data(){
return {
nowTime:''
}
},
2.给定一个div
<div>{{nowTime}}</div>
3.js部分
//显示当前时间(年月日时分秒)
timeFormate(timeStamp) {
let year = new Date(timeStamp).getFullYear();
let month =new Date(timeStamp).getMonth() + 1 < 10? "0" + (new Date(timeStamp).getMonth() + 1): new Date(timeStamp).getMonth() + 1;
let date =new Date(timeStamp).getDate() < 10? "0" + new Date(timeStamp).getDate(): new Date(timeStamp).getDate();
let hh =new Date(timeStamp).getHours() < 10? "0" + new Date(timeStamp).getHours(): new Date(timeStamp).getHours();
let mm =new Date(timeStamp).getMinutes() < 10? "0" + new Date(timeStamp).getMinutes(): new Date(timeStamp).getMinutes();
let ss =new Date(timeStamp).getSeconds() < 10? "0" + new Date(timeStamp).getSeconds(): new Date(timeStamp).getSeconds();
this.nowTime = year + "年" + month + "月" + date +"日"+" "+hh+":"+mm+':'+ss ;
},
nowTimes(){
this.timeFormate(new Date());
setInterval(this.nowTimes,1000);
this.clear()
},
clear(){
clearInterval(this.nowTimes)
this.nowTimes = null;
}
4.复制粘贴即可用,主要是使用定时器,每秒调用,最后清除定时器,清除函数
在vue项目中显示实时时间(年月日时分秒)的更多相关文章
- Swift3.0 iOS获取当前时间 - 年月日时分秒星期
Swift3.0 iOS获取当前时间 - 年月日时分秒星期func getTimes() -> [Int] { var timers: [Int] = [] // 返回的数组 let calen ...
- C#WinForm中显示实时时间:年/月/日 时/分/秒 星期X
//加载窗体时 string weekstr = ""; private void Form22_Load(object sender, EventArgs e) { this.t ...
- sqlserver 获取时间年月日时分秒
转自:http://blog.itpub.net/14766526/viewspace-1156100/ select GETDATE() as '当前日期',DateName(year,GetDat ...
- C#:获取时间年月日时分秒格式
//获取日期+时间 DateTime.Now.ToString(); // 2008-9-4 20:02:10 DateTime.Now.ToLocalTime().ToStri ...
- java 获得当前时间 年月日时分秒 星期几
<%SimpleDateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");//设置日期格式SimpleDat ...
- js如何获得系统时间年月日时分秒
javascript 自带有个对象(构造函数),Date().下面是代码: 回答一: var now = new Date(); var nowTime = now.toLocaleString() ...
- mssql 格式化字符串 /时间 年月日时分秒
比如:1 想格式化 000001,100 格式化为000100: 思路是这样的 1000000 +格式化的数字 取后6位: select right(cast(power(10,6) as var ...
- vue 项目中实用的小技巧
# 在Vue 项目中引入Bootstrap 有时在vue项目中会根据需求引入Bootstrap,而Bootstrap又是依赖于jQuery的,在使用npm按照时,可能会出现一系列的错误 1.安装jQu ...
- vue项目中遇到的那些事。
前言 有好几天没更新文章了.这段实际忙着做了一个vue的项目,从 19 天前开始,到今天刚好 20 天,独立完成. 做vue项目做这个项目一方面能为工作做一些准备,一方面也精进一下技术. 技术栈:vu ...
随机推荐
- 计算机网络 From Mr.Liu
引言 本博客摘自Mr.Liu,原帖请点击这里. 感谢Mr.Liu,这个文章很充分的描述了计算机网络的核心知识点. 我还在学习中,所以没有进行自己的转述.图片因为是copy代码而没有获得,想看更详尽的, ...
- .NET CORE应用程序启动
ASP.NET Core 应用是在其 Main 方法中创建 Web 服务器的控制台应用: Main 方法调用 WebHost.CreateDefaultBuilder,通过生成器模式来创建web主机. ...
- 编译Qualcomm的Hexagon exampls错误
在下载了Qualcomm的Hexagon SDK 351版本之后,想跑里面的examples,然后参照文档的说,比如在examples/common/sobel3x3_v60目录下面,先执行了SDK根 ...
- SecureCRT的下载、安装( 过程非常详细!!值得查看)
SecureCRT的下载.安装( 过程非常详细!!值得查看) 简单介绍下SecureCRT 一.SecureCRT的下载 二.SecureCRT的安装 简单介绍下SecureCRT SecureCRT ...
- MySQL 什么是索引?
该文为< MySQL 实战 45 讲>的学习笔记,感谢查看,如有错误,欢迎指正 一.索引简介 索引就类似书本的目录,作用就是方便我们更加快速的查找到想要的数据. 索引的实现方式比较多,常见 ...
- alpine安装telnet等工具
alpine确实是很精简,但是对于熟悉了centos和ununtu的个人来说,实在是不习惯. 因此,记录关于alpine的一些包安装,以及操作细节(逐渐补充). 1. telnet >>& ...
- win10环境下安装mysql-8.0.18-winx64
下载mysql安装包,然后解压到你想安装的目录下,我下载的是mysql-8.0.18-winx64 Windows 上安装 MySQL 相对来说会较为简单,最新版本可以在 MySQL 下载 中下载中查 ...
- AI数据标注行业面临的5大发展困局丨曼孚科技
根据艾瑞咨询发布的行业白皮书显示,2018年中国人工智能基础数据服务市场规模为25.86亿元,预计2025年市场规模将突破113亿元,行业年复合增长率达到了23.5%. 作为人工智能产业的基石,数据 ...
- LeetCode30 Hard 查找所有子串
本文始发于个人公众号:TechFlow,原创不易,求个关注 链接 Substring with Concatenation of All Words 难度 Hard 描述 给定一个字符串s作为母串,和 ...
- python三级菜单制作 day4
需求:可依次选择进入各子菜单可从任意一层往回退到上一层可从任意一层退出程序所需新知识点:列表.字典 数据结构: menu = { '北京':{ '海淀':{ ...