频道栏目
首页 > 资讯 > JavaScript > 正文

关于jsDate时间转换毫秒中文自定义(代码教程)

18-07-11        来源:[db:作者]  
收藏   我要投稿

关于jsDate时间转换毫秒中文自定义(代码教程)

Date.prototype.toLocaleString=function(){
  var year=this.getFullYear();
  if((this.getMonth()+1)<10){
    var month="0"+(this.getMonth() + 1);
  }
  if((this.getDate()<10)){
    var day="0"+this.getDate();
  }
  // return this.getFullYear() + "-" + (this.getMonth() + 1) + "-" + this.getDate();
  return year+'-'+month+'-'+day;
}

有些时间格式要求这样,可以在里面判断自己修改,这样定义就是:2010-01-01

Date.prototype.toLocaleString = function() {
          return this.getFullYear() + "年" + (this.getMonth() + 1) + "月" + this.getDate() + "日 " + this.getHours() + "点" + this.getMinutes() + "分" + this.getSeconds() + "秒";
    };

2010年01月01日 12点12分12秒

new Date.getTime()

把时间转换成毫秒数

var newDate=new Date().getTime();

console.log(newDate);//把当前时间转换成毫秒

var oldTime = (new Date("2012/12/25 20:11:11")).getTime(); //得到毫秒数

console.log(oldTime);

var oldTime = (new Date("2012/12/25 20:11:11")).getTime(); //得到毫秒数

var newTime = new Date(oldTime); //就得到普通的时间了

console.log(newTime.toLocaleString());//转换成中文

相关TAG标签
上一篇:h5高度塌陷代码实例
下一篇:javascript模块化编程之AMD模块化编程规范实例讲解
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站