var myDate = new Date();
myDate.getYear(); //获取当前年份(2位)
myDate.getFullYear(); //获取完整的年份(4位,1970-????)
myDate.getMonth(); //获取当前月份(0-11,0代表1月)
myDate.getDate(); //获取当前日(1-31)
myDate.getDay(); //获取当前星期X(0-6,0代表星期天)
myDate.getTime(); //获取当前时间(从1970.1.1开始的毫秒数)
myDate.getHours(); //获取当前小时数(0-23)
myDate.getMinutes(); //获取当前分钟数(0-59)
myDate.getSeconds(); //获取当前秒数(0-59)
myDate.getMilliseconds(); //获取当前毫秒数(0-999)
myDate.toLocaleDateString(); //获取当前日期
var mytime=myDate.toLocaleTimeString(); //获取当前时间
myDate.toLocaleString( ); //获取日期与时间

————————————————

// 对Date的扩展,将 Date 转化为指定格式的String
// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
// 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
// 例子:
// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
// (new Date()).Format("yyyy-M-d h:m:s.S")      ==> 2006-7-2 8:9:4.18
Date.prototype.Format = function (fmt) {var o = {"M+": this.getMonth() + 1, //月份 "d+": this.getDate(), //日 "H+": this.getHours(), //小时 "m+": this.getMinutes(), //分 "s+": this.getSeconds(), //秒 "q+": Math.floor((this.getMonth() + 3) / 3), //季度 "S": this.getMilliseconds() //毫秒 };if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));for (var k in o)if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));return fmt;
}调用:
var time1 = new Date().Format("yyyy-MM-dd");
var time2 = new Date().Format("yyyy-MM-dd HH:mm:ss");

————————————————

<!DOCTYPE html><html class=''>
<head>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script><style>* {margin: 0;padding: 0;}.backgroundAnimation{background: red;width: 500px;height: 500px;}#bugg{margin:50%;background:green;width: 100px;height: 30px;}</style><body><!-- option-->
<div class="backgroundAnimation" ><H1 id="Test"></H1><input id="bugg" onClick="aa()" type="button"  value="在线测试按钮" ></input></div></body><script>// 对Date的扩展,将 Date 转化为指定格式的String
// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
// 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
// 例子:
// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
// (new Date()).Format("yyyy-M-d h:m:s.S")      ==> 2006-7-2 8:9:4.18
Date.prototype.Format = function (fmt) {var o = {"M+": this.getMonth() + 1, //月份 "d+": this.getDate(), //日 "H+": this.getHours(), //小时 "m+": this.getMinutes(), //分 "s+": this.getSeconds(), //秒 "q+": Math.floor((this.getMonth() + 3) / 3), //季度 "S": this.getMilliseconds() //毫秒 };if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));for (var k in o)if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));return fmt;
}function aa(){var time1 = new Date().Format("yyyy-MM-dd");var time2 = new Date().Format("yyyy-MM-dd HH:mm:ss");alert(time1);alert(time2);
}</script>
</html>

JS获取当前时间并格式化“yyyy-MM-dd HH:mm:ss“相关推荐

  1. js获取当前时间并格式化

    获取当前时间,格式化为2022-12-28 11:17:05 getCurrentTime() {//格式:yyyy-MM-dd HH:mm:ssvar _this = this;let yy = n ...

  2. Kettle5.2 couldn't convert string [...] to a date using format [yyyy/MM/dd HH:mm:ss.SSS]

    使用kettle出现 couldn't convert string [...] to a date using format [yyyy/MM/dd HH:mm:ss.SSS] 试了各种方法,最后发 ...

  3. C# 中的年月日时分秒 yyyy MM dd HH mm ss

    C# 中的年月日时分秒 yyyy MM dd HH mm ss 其中大小写含义不同,不能混用 年:yyyy 月:MM 日:dd(1-31) DD(0-365) 时:hh:12小时制 HH:24小时制 ...

  4. 【怒怼老乔】苹果手机ios系统居然特喵的不支持日期yyyy-MM-dd HH:mm:ss.ms,只支持 yyyy/MM/dd HH:mm:ss

    苹果手机ios系统居然特喵的 不支持日期yyyy-MM-dd HH:mm:ss.ms, 只支持yyyy/MM/dd HH:mm:ss 我只能用 .replace(/\-/g,'\/'); 来替换掉了, ...

  5. 【JS】获取当前时间,且格式为yyyy-MM-dd hh:mm:ss

    我们在前端获取当前时间: var nowDate = new Date(); 时间格式为: Sun May 27 2018 19:28:09 GMT+0800 (中国标准时间) 但是我们想在页面上显示 ...

  6. 时间格式区别之YYYY/MM/dd HH:mm 与 yyyy/MM/dd HH:mm

    1. 相应的业务场景 1.1 场景简介 正值2019年末,2020年初之际,系统日期时间为2019/12/31而系统报表却出现了2020/12/31的日期. 1.2 代码案例如下 2.Java中YYY ...

  7. JAVA 最简单获取系统时间代码 LocalDateTime( 以yyyy-MM-dd HH:mm:ss.SSS格式显示)

    直接上代码,简单粗暴: import java.time.LocalDateTime; import java.time.format.DateTimeFormatter;/*** @Author : ...

  8. spring boot + vue 前后端分离时间戳转换为 yyyy:MM:dd HH:mm:ss格式

    后端 1.model(entity)注释直接转换 当返回类型为resultMap,在entity类里面相应属性上加上以下注释 @JsonFormat(pattern="yyyy-MM-dd ...

  9. js时间格式化 YYYY/MM/DD HH:MM:SSS

    /*** 将"2018-05-19T08:04:52.000+0000"这种格式的时间转化为正常格式* @param time*/ function timeFormat(time ...

最新文章

  1. 2018-3-18Zookeep
  2. java map在前端遍历_遍历循环输出map的几种方式
  3. 苹果数据线不能充电_外媒痛批苹果!iPhone 12不送充电器绝非为环保,理由太真实!|充电器|数据线|手机|iphone...
  4. php获取当天的开始时间和结束时间
  5. 利用python爬虫(part2)--urllib.parse模块
  6. 【AT987】高橋君【组合数】【莫队】
  7. windows cmd 定义和使用变量
  8. 手动挖第一桶金,10日赚3十万元
  9. 第六章节 多态 (多态的概述)
  10. MFC中 给基于CFormView的单文档添加背景图片
  11. php开发我的收藏,我的收藏列表 · 老猫带你玩转ThinkPHP5 API开发 · 看云
  12. 粒子群优化算法matlab实现,粒子群优化算法的MATLAB程序实现+源程序
  13. 面试结束后,向面试官要问的问题
  14. 如何从零配置腾讯云cdn加速服务?
  15. 至强cpu能装linux吗,至强四核CPU Xeon 安装Linux系统后 能利用到4个核吗?
  16. python警示:WARNING: Ignoring invalid distribution
  17. warning: variable ‘a‘ set but not used [-Wunused-but-set-variable]
  18. c++串口配置及DCB结构体
  19. php对接linepay支付
  20. 2021年煤气考试报名及煤气考试APP

热门文章

  1. php程序员学什么语言好就业_十几岁的女生学什么专业就业前景好?
  2. PowerBuilder基础知识
  3. LeetCode 312. 戳气球(Java)
  4. 中国特种线市场趋势报告、技术动态创新及市场预测
  5. 什么是首选的Bash shebang?
  6. LinuxProbe 0x15 SAMBA文件共享服务、NFS网络文件系统、AutoFs自动挂载服务、DNS域名解析服务
  7. Chrome 安装失败 错误代码 0X80070057
  8. 银河仿真计算机说明书,“银河”高性能分布仿真计算机系统诞生
  9. 计算机网络-自顶向下-Web应用2(Cookie、Web缓存、条件GET详解)
  10. 磁道是同心圆还是同心环