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项目中显示实时时间(年月日时分秒)的更多相关文章

  1. Swift3.0 iOS获取当前时间 - 年月日时分秒星期

    Swift3.0 iOS获取当前时间 - 年月日时分秒星期func getTimes() -> [Int] { var timers: [Int] = [] // 返回的数组 let calen ...

  2. C#WinForm中显示实时时间:年/月/日 时/分/秒 星期X

    //加载窗体时 string weekstr = ""; private void Form22_Load(object sender, EventArgs e) { this.t ...

  3. sqlserver 获取时间年月日时分秒

    转自:http://blog.itpub.net/14766526/viewspace-1156100/ select GETDATE() as '当前日期',DateName(year,GetDat ...

  4. C#:获取时间年月日时分秒格式

    //获取日期+时间 DateTime.Now.ToString();            // 2008-9-4 20:02:10 DateTime.Now.ToLocalTime().ToStri ...

  5. java 获得当前时间 年月日时分秒 星期几

    <%SimpleDateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");//设置日期格式SimpleDat ...

  6. js如何获得系统时间年月日时分秒

    javascript 自带有个对象(构造函数),Date().下面是代码: 回答一: var now = new Date();  var nowTime = now.toLocaleString() ...

  7. mssql 格式化字符串 /时间 年月日时分秒

    比如:1 想格式化 000001,100 格式化为000100: 思路是这样的 1000000 +格式化的数字 取后6位: select   right(cast(power(10,6) as var ...

  8. vue 项目中实用的小技巧

    # 在Vue 项目中引入Bootstrap 有时在vue项目中会根据需求引入Bootstrap,而Bootstrap又是依赖于jQuery的,在使用npm按照时,可能会出现一系列的错误 1.安装jQu ...

  9. vue项目中遇到的那些事。

    前言 有好几天没更新文章了.这段实际忙着做了一个vue的项目,从 19 天前开始,到今天刚好 20 天,独立完成. 做vue项目做这个项目一方面能为工作做一些准备,一方面也精进一下技术. 技术栈:vu ...

随机推荐

  1. 迁移桌面程序到MS Store(14)——APPX嵌入WCF Service以Admin权限运行

    Windows10 1809版本开始,微软又对UWP开放了新的Capability:AllowElevation. 通过这个新的Capability,UWP APP能够在运行时向用户请求Admin权限 ...

  2. redis 5.0.7 源码阅读——动态字符串sds

    redis中动态字符串sds相关的文件为:sds.h与sds.c 一.数据结构 redis中定义了自己的数据类型"sds",用于描述 char*,与一些数据结构 typedef c ...

  3. Oracle v$session视图显示客户端IP地址

    在Oracle数据库中,我们使用session相关视图(v$session.v$active_session_history,dba_hist_active_session_history等)查找问题 ...

  4. P1651 塔

    ----------------- 链接:Miku ----------------- 这是一道dp题,我么很容易发现这点. 数据范围很大,如果直接用两个塔的高度当状态,很危险,我们就必须要考虑一下优 ...

  5. 五种编程语言解释数据结构与算法——顺序表3(JavaScript与Python语言实现)

    7.JavaScript语言实现 7.1.用ES6语法编写顺序表类 //1.创建类 class MyList { //1. initList(&L):初始化表.构造一个空的线性表.放回值应该是 ...

  6. 桌面粉笔功能.有window ink功能区开启的快捷键

    功能区开启的快捷键 方法1: win+W唤出工作区,可以直接点击,但是没有快捷键.prtsc是直接截取屏幕(国际通用)然后在画图打开或直接粘贴于某处都可以. 方法2:快捷键是 Windows 徽标键 ...

  7. 处理方法返回值void

    1.默认响应效果:根据请求url寻找相应页面 1.1.配置的视图解析器 <!--配置视图解析器--> <bean id="internalResourceViewResol ...

  8. C# MVC 中自定义权限特性[Authorize]中对于Ajax访问的处理

    在MVC中定义自己的权限特性. 下例中是简单的登录判断,登录信息存与Session中,如果Session中没有登录信息,那么就不通过. 在处理无权限的时候,判断当前请求是否为Ajax请求,如果是Aja ...

  9. python文件操作汇总day7

    Python处理文件 文件操作分为读.写.修改,我们先从读开始学习 读文件 示例1: f = open(file='D:/工作日常/兼职白领学生空姐模特护士联系方式.txt',mode='r',enc ...

  10. Q&A in 2018 - Q1

    Those questions Simply write down questions that ever frustrated me a little: How to convert unix ti ...