格式化时间
参数: formatStr 格式化串 y年,m月,d日,h小时,i分钟,s秒钟 缺省值 "y-m-d h:i:s"
fdate 要格式化的时间(时间戳)UTC秒数 缺省值 当前时间
实例: formatDate() 当前时间默认格式 如 2011-4-12 12:51:12
formatDate('y/m/d', 2132132131) 某时间格式为 年月日 如 2010/12/5
date.getYear(); //获取当前年份(2位)
date.getFullYear(); //获取完整的年份(4位,1970-????)
date.getMonth(); //获取当前月份(0-11,0代表1月)
date.getDate(); //获取当前日(1-31)
date.getDay(); //获取当前星期X(0-6,0代表星期天)
date.getTime(); //获取当前时间(从1970.1.1开始的毫秒数)
date.getHours(); //获取当前小时数(0-23)
date.getMinutes(); //获取当前分钟数(0-59)
date.getSeconds(); //获取当前秒数(0-59)
date.getMilliseconds(); //获取当前毫秒数(0-999)
date.toLocaleDateString(); //获取当前日期
var mytime=date.toLocaleTimeString(); //获取当前时间
date.toLocaleString( ); //获取日期与时间
function formatDate(formatStr, fdate)
{
var fTime, fStr = 'ymdhis';
if (!formatStr)
formatStr= "y-m-d h:i:s";
if (fdate)
fTime = new Date(fdate);
else
fTime = new Date();
var formatArr = [
fTime.getFullYear().toString(),
(fTime.getMonth()+1).toString(),
fTime.getDate().toString(),
fTime.getHours().toString(),
fTime.getMinutes().toString(),
fTime.getSeconds().toString()
]
for (var i=0; i<formatArr.length; i++)
{
formatStr = formatStr.replace(fStr.charAt(i), formatArr[i]);
}
return formatStr;
}
时间转毫秒
//时间转毫秒
function c1(data){
var b = (new Date(data)).getTime();
return b;
}
//显示:当前日期加时间(如:2009-06-12 12:00)
function CurentTime()
{
var now = new Date();
var year = now.getFullYear(); //年
var month = now.getMonth() + 1; //月
var day = now.getDate(); //日
var hh = now.getHours(); //时
var mm = now.getMinutes(); //分
var clock = year + "-";
if(month < 10)
clock += "0";
clock += month + "-";
if(day < 10)
clock += "0";
clock += day + " ";
if(hh < 10)
clock += "0";
clock += hh + ":";
if (mm < 10) clock += '0';
clock += mm;
return(clock);
}