js获取当前系统时间

function show(){
var mydate = new Date();
var str = "" + mydate.getFullYear() + "年";
str += (mydate.getMonth()+1) + "月";
str += mydate.getDate() + "日";
str+=mydate.getHours() + "时";
str+=mydate.getMinutes() + "分";
str+=mydate.getSeconds() + "秒";
return str;


}
  function show1(){
function p(s) {
return s < 10 ? '0' + s: s;
}

var myDate = new Date();
//获取当前年
var year=myDate.getFullYear();
//获取当前月
var month=myDate.getMonth()+1;
//获取当前日
var date=myDate.getDate();
var h=myDate.getHours(); //获取当前小时数(0-23)
var m=myDate.getMinutes(); //获取当前分钟数(0-59)
var s=myDate.getSeconds();

var now=year+'-'+p(month)+"-"+p(date)+" "+p(h)+':'+p(m)+":"+p(s);
return now;

}

将当前时间存到点击的li里面去


点击之后

两种时间格式随便用都可以




posted @ 2016-11-28 09:49  liucong2016  阅读(6821)  评论(0编辑  收藏  举报