方法一:

Date.prototype.format = function (format) {
var args = {
"M+": this.getMonth() + 1,
"d+": this.getDate(),
"h+": this.getHours(),
"m+": this.getMinutes(),
"s+": this.getSeconds(),
"q+": Math.floor((this.getMonth() + 3) / 3), //quarter
"S": this.getMilliseconds()
};
if (/(y+)/.test(format))
format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var i in args) {
var n = args[i];
if (new RegExp("(" + i + ")").test(format))
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? n : ("00" + n).substr(("" + n).length));
}
return format;
}; 调用方法 alert(new Date().format("yyyy-MM-dd hh:mm:ss:S")); alert(new Date().format("yyyy-MM-dd hh:mm:ss"));

------------------------------------------------------------------------------------

方法二:

function getNowFormatDate() {
var date = new Date();
var seperator1 = "-";
var seperator2 = ":";
var month = date.getMonth() + 1;
var strDate = date.getDate();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
var currentdate = date.getYear() + seperator1 + month + seperator1 + strDate
+ " " + date.getHours() + seperator2 + date.getMinutes()
+ seperator2 + date.getSeconds();
return currentdate;
}

------------------------------------------------------------------------------------

方法三:

function curDateTime(){
var d = new Date();
var year = d.getYear();
var month = d.getMonth()+1;
var date = d.getDate();
var day = d.getDay();
var hours = d.getHours();
var minutes = d.getMinutes();
var seconds = d.getSeconds();
var ms = d.getMilliseconds();
var curDateTime= year;
if(month>9)
curDateTime = curDateTime +"-"+month;
else
curDateTime = curDateTime +"-0"+month;
if(date>9)
curDateTime = curDateTime +"-"+date;
else
curDateTime = curDateTime +"-0"+date;
if(hours>9)
curDateTime = curDateTime +""+hours;
else
curDateTime = curDateTime +"0"+hours;
if(minutes>9)
curDateTime = curDateTime +":"+minutes;
else
curDateTime = curDateTime +":0"+minutes;
if(seconds>9)
curDateTime = curDateTime +":"+seconds;
else
curDateTime = curDateTime +":0"+seconds;
return curDateTime;
} alert(curDateTime());

js 获取当前日期时间3种格式化方法 yyyy-mm-dd hh:MM:ss的更多相关文章

  1. JS获取当前日期时间及JS日期格式化

    Js获取当前日期时间: var myDate = new Date(); myDate.getYear(); //获取当前年份(2位) myDate.getFullYear(); //获取完整的年份( ...

  2. Js获取当前日期时间及其它操作

    Js获取当前日期时间及其它操作var myDate = new Date();myDate.getYear(); //获取当前年份(2位)myDate.getFullYear(); //获取完整的年份 ...

  3. Js获取当前日期时间及时间相关操作

    Js获取当前日期时间及时间格式 var myDate = new Date();myDate.getYear();        //获取当前年份(2位)myDate.getFullYear();   ...

  4. 【转】Js获取当前日期时间及其它操作

    Js获取当前日期时间及其它操作 原文地址:http://www.cnblogs.com/carekee/articles/1678041.html var myDate = new Date();my ...

  5. [转]Js获取当前日期时间及其它操作

    转载自:http://www.cnblogs.com/carekee/articles/1678041.html Js获取当前日期时间及其它操作 var myDate = new Date();myD ...

  6. Js 获取当前日期时间及其它操作(转)

    Js获取当前日期时间及其它操作 var myDate = new Date();myDate.getYear();        //获取当前年份(2位)myDate.getFullYear();   ...

  7. Js获取当前日期时间及其它格式化操作

    Js获取当前日期时间及其它操作 var myDate = new Date();myDate.getYear();        //获取当前年份(2位)myDate.getFullYear();   ...

  8. js 获取当前日期时间 格式为 yyyy-mm-dd hh:MM:ss

    ------------------------------------------------------------------------------------ js 获取当前日期时间 格式为 ...

  9. Js获取当前日期时间

    Js获取当前日期时间 var myDate = new Date(); myDate.getYear(); //获取当前年份(2位) myDate.getFullYear(); //获取完整的年份(4 ...

随机推荐

  1. ACM water

    1000  纯属适应题 1003  做的时候花了很久,现在看好像也不难 1004  适应题,求下平均就行 1005  要读懂题就行 1007  逆序数,discuss方法 1046  全部暴搜一遍.. ...

  2. 3数字cn域名延续数字域名火爆行情! 珍品域名 593.cn 出售

      近日, 域名投资者小维放出珍藏多年的珍品域名593.cn, 据悉该域名将参加易名中国举办的数字域名专场拍卖活动,将以1元标价起拍.   域名593.cn,数字“593”谐音“我就上.吾就上.我就商 ...

  3. MVC视图请求流程视图

    /*         *视图请求流程         *当接受到home/index请求时         *先去找viewstart.cshtml视图,再去加载index.cshtml视图      ...

  4. jvm的代码缓存耗尽导致性能下降

    在没遇到这个问题之前,我对JVM的解释模式与编译模式的代码性能相差有多大,是没有感觉的,只是觉得编译模式会比解释模式性能好那么一点点吧. 但是经历过这次以后,让我对JVM的即时编译产生了兴趣.先来看看 ...

  5. PHP 数组转码

    /** * 数组转码 * @param array $arr 要转码的数组 * @param string $in_charset 输入的字符集 * @param string $out_charse ...

  6. # C/C++的笔试题目

    p,li { white-space: pre-wrap } # C/C++的笔试题目 + include<> 和include"" 的区别 + sizeof操作符与字 ...

  7. nginx-502错误,老是提示busy.优化php-fpm如下

    [global]pid = /usr/local/php/var/run/php-fpm.piderror_log = /usr/local/php/var/log/php-fpm.loglog_le ...

  8. web前端响应式

    一.响应式概述: 不仅仅是通过屏幕尺寸来动态改变页面容器的宽度等,完整的响应式网站的实现需要考虑到这些问题:响应式布局.响应式html和css.响应式媒体.响应式javascript. 二.移动端布局 ...

  9. C#动态webservice调用接口 (JAVA,C#)

    C#动态webservice调用接口 using System; using System.Collections; using System.IO; using System.Net; using ...

  10. ANY数据类型的使用

      程序举例: TAR1 #T_AR1 //save addressregister 1 TAR2 #T_AR2 //save addressregister 2 LAR1 P##DST_BLOCK_ ...