zoukankan      html  css  js  c++  java
  • 201506101252_《JavaScript时间戳、转义、类型转化、继承》

    例如要得到:20150610125348,可以这么做:

    1. 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 ss = now.getSeconds();           //秒

      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 + ":";

      if (ss < 10) clock += '0';
      clock += ss;
      return(clock);
      };

    alert(+new Date(CurentTime()));  

    二. 转义

    var url = encodeURIComponent('http://segmentfault.com/questions/newest');  //http://%&54....

    decodeURIComponent(url);  //http://segmentfault.com/questions/newest

    三. 小数点后几位

    var someNum.toFixed(2);   //保留小数点后两位

    四. 检测类型

    var toJudge = Object.prototype.toString;

    var whatType = toJudge.call(new Date);

    alert(whatType);  //object,date

    五. 继承

    function  Shape() {

      this.x = 0;

          this.y = 0;

    }

    Shape.prototype.move = function(x,y) {

      this.x += x;

          this.y += y;

          console.info("This is moving action..."); 

    }

    function Rectangle() {

      Shape.call(this);

    }

    var rect = new Rectangle();

    alert(rect instanceof Rectangle); //true

    alert(rect instanceof Shape);  //true

    rect.move(2,3);

    前端-语言
  • 相关阅读:
    Oracle SQL性能优化
    spring aop简单日志实例
    一个简单的Spring AOP例子
    jQuery的三种$()
    Mac 上的 outlook 一直让输入密码
    idea 中设置成公司规范的代码格式
    Java 中的锁——Lock接口
    TimeUnit枚举类
    Thread.join()的使用
    java线程的等待、通知机制【读书笔记】
  • 原文地址:https://www.cnblogs.com/beesky520/p/4565783.html
Copyright © 2011-2022 走看看