当前位置: 移动技术网 > IT编程>开发语言>JavaScript > 关于jsDate时间转换毫秒中文自定义(代码教程)

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

2018年10月05日  | 移动技术网IT编程  | 我要评论

关于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());//转换成中文

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网