JS中的String.Math.Date

//今天放假没看东西,贴上以前的基础,没事看着玩

// String->->

var myStr = "My name is LiuYashion";
        console.log(    myStr.length        );                      //21
        console.log(    myStr.charAt(0)        );                 //M
        console.log(    myStr.charCodeAt(0)        );        //77 (M)
        console.log(    myStr.indexOf("n")        );           //3
        console.log(    myStr.lastIndexOf("n")        );    //20
       
        console.log(    String.fromCharCode(77)        );    //M
       
        console.log(     myStr.replace("My","His")     );    //His name is LiuYashion 只能换一次,最前面的一个
       
        console.log(    myStr.substring(11,21)    );        //LiuYashion,包含11,不包含21
       
        console.log(    myStr.toLowerCase()    );            //my name is liuyashion
        console.log(    myStr.toUpperCase()    );            //MY NAME IS LIUYASHION
       
    var myStr_1 = "         My name is LiuYashion          ";   
        console.log(    myStr_1        );                      // My name is LiuYashion         
        console.log(    myStr_1.trim()        );            //My name is LiuYashion    
       
       
// Number->->

var myArr = ["M","y"," ","n","a","m","e"," ","i","s"," ","L","i","u","Y","a","s","h","i","o","n"];   
        console.log(    myArr.length        );                     //21
        console.log(    myArr.indexOf("n")        );           //3
        console.log(    myArr.lastIndexOf("n")        );    //20
       
       
//     Math->->
   
    console.log(    Math.round(3.6)        );            //4     四舍五入
    console.log(    Math.abs(-3.3)        );              //3.3    绝对值
    console.log(    Math.ceil(-3.3)        );               //-3     向上取整
    console.log(    Math.floor(-3.3)    );                 //-4    向下取整
    console.log(    Math.pow(2,3)        );              //8        2的3次方
    console.log(    Math.sqrt(9)        );                 //3        9开方
    console.log(    Math.max(3.3,15,30)        );        //30    最大值
   
   
   
   
   
// Date->->
    var myDate  = new Date(‘2016/3/21 23:11:11‘);   
    var nowDate = new Date();            //Wed Mar 23 2016 11:02:22 GMT+0800 (中国标准时间)
   
    console.log(    nowDate.getFullYear()        );           //2016 (number类型)
    console.log(    nowDate.getMonth()        );             //2 月份是0-11
    console.log(    nowDate.getDate()        );              //23 日期是从1开始
   
    console.log(    myDate.getDay()        );                 //1 星期一
    console.log(    myDate.getHours()        );             //23
    console.log(    myDate.getMinutes()        );         //11
    console.log(    myDate.getSeconds()        );        //11
   
    console.log(    myDate.setFullYear(2008)    );          //1220886671000 距离1970.1.1的毫秒数.
    console.log("-------------"+myDate)
    console.log(    myDate.setMonth(8)        );             //1220886671000 距离1970.1.1的毫秒数
    console.log(    myDate.setDate(8)        );                //1220886671000 距离1970.1.1的毫秒数
   
    console.log(    myDate    );    //Mon Sep 08 2008 23:11:11 GMT+0800 (中国标准时间)
   
   
    var firstDate   = new Date(‘2016/3/24 11:11:11‘);
    var secondDate  = new Date();
   
    var spare = firstDate - secondDate;
   
    var spare_s = parseInt(spare/1000);     //    spare_s            总共的秒数
    var spare_seconds = spare_s%60;         //    spare_seconds    余下秒数
   
    var spare_m = parseInt(spare_s/60);     //     spare_m            总共分钟数
    var spare_minutes = spare_m%60;            //    spare_minutes    余下的分钟
   
    var spare_h = parseInt(spare_m/60);     //    spare_h            总共小时数   
    var spare_hours = spare_h%24;            //    spare_hours        余下小时数
       
    var spare_days = parseInt(spare_h/24);    //    spare_days        总共的天数
   
    console.log(spare_days+"天"+spare_hours+"小时"+spare_minutes+"分钟"+spare_seconds+"秒");
    //    0天21小时18分钟15秒
   
    var date_1 = new Date(‘1970/1/1‘);
    console.log(    Date.parse(date_1)    );    //946656000000,距离1970.1.1的毫秒数
   
   
    var my_date = new Date();
    console.log( my_date.getFullYear()+"/"+ (my_date.getMonth()+1) +"/"+ my_date.getDate() );
    //2016/3/23

时间: 2024-08-11 03:24:21

JS中的String.Math.Date的相关文章

js中获取时间new date()的用法

js中获取时间new date()的用法 获取时间:   var myDate = new Date();//获取系统当前时间 获取特定格式的时间: 1 myDate.getYear(); //获取当前年份(2位) 2 myDate.getFullYear(); //获取完整的年份(4位,1970-????) 3 myDate.getMonth(); //获取当前月份(0-11,0代表1月) 4 myDate.getDate(); //获取当前日(1-31) 5 myDate.getDay();

javaScript系列:js中获取时间new Date()详细介绍

var myDate = new Date();myDate.getYear(); //获取当前年份(2位)myDate.getFullYear(); //获取完整的年份(4位,1970-????)myDate.getMonth(); //获取当前月份(0-11,0代表1月)myDate.getDate(); //获取当前日(1-31)myDate.getDay(); //获取当前星期X(0-6,0代表星期天) 何问起 hovertree.commyDate.getTime(); //获取当前时

js中获取时间new Date()详细介绍

var myDate = new Date();myDate.getYear(); //获取当前年份(2位)myDate.getFullYear(); //获取完整的年份(4位,1970-????)myDate.getMonth(); //获取当前月份(0-11,0代表1月)         // 所以获取当前月份是myDate.getMonth()+1; myDate.getDate(); //获取当前日(1-31)myDate.getDay(); //获取当前星期X(0-6,0代表星期天)m

小程序 js中获取时间new date()的用法(网络复制过来自用)

js中获取时间new date()的用法 获取时间: 1 var myDate = new Date();//获取系统当前时间 获取特定格式的时间: 1 myDate.getYear(); //获取当前年份(2位) 2 myDate.getFullYear(); //获取完整的年份(4位,1970-????) 3 myDate.getMonth(); //获取当前月份(0-11,0代表1月) 4 myDate.getDate(); //获取当前日(1-31) 5 myDate.getDay();

Js中获取时间 new date()的用法

获取时间: var myDate = new Date();//获取系统当前时间 myDate.getYear(); //获取当前年份(2位) myDate.getFullYear(); //获取完整的年份(4位,1970-????) myDate.getMonth(); //获取当前月份(0-11,0代表1月) myDate.getDate(); //获取当前日(1-31) myDate.getDay(); //获取当前星期X(0-6,0代表星期天) myDate.getTime(); //获

js中的函数,Date对象,Math对象和数组对象

函数就是完成某个功能的一组语句,js中的函数由关键字 function + 函数名 + 一组参数定义;函数在定义后可以被重复调用,通常将常用的功能写成一个函数,利用函数可以使代码的组织结构更多清晰. 其语法结构为 function funName (arg0, arg1, … argN){        //statements    } function say_hello (name, msg){ alert(“hello”+ name + “:”+ msg); } say_hello(“d

JS中常用的Math方法

1.min()和max()方法 Math.min()用于确定一组数值中的最小值.Math.max()用于确定一组数值中的最大值. alert(Math.min(2,4,3,6,3,8,0,1,3)); //最小值 alert(Math.max(4,7,8,3,1,9,6,0,3,2)); //最大值 2.舍入方法 Math.ceil()执行向上舍入,即它总是将数值向上舍入为最接近的整数: Math.floor()执行向下舍入,即它总是将数值向下舍入为最接近的整数: Math.round()执行标

js中的String数据类型

string中包含一些特殊的字符字面量,又叫转义序列,\n 意思是换行,\t 意为制表,\b意为空格,\r回车,\\斜杠. 1.ECMAScript中字符串是不可变的. 2.转换字符串的方法:toString() 返回相应值的字符串形态.null和undefined没有此方法,其他都有. 3.在不知道要转换的值是不是null或undefined的情况下,可以使用转型函数String(),这个函数能将任意值转换成字符串. var value1=null; var value2=undefined;

js中的string是只读的!!!

今天写排序的时候没看到string有sort方法 然后就打算自己实现快排, 想当然地觉得string能迭代就把它当作了array,跟其它语言搞混了... 比如str = "bca",str[0] = str[1],结果肯定不会变的 =_=,str依然是"bca" 所以我的排序爆栈了...被自己蠢到了... 此时突然回忆起一句话,ECMAScript规定string不可变, 也就是说我们平时看到的字符串拼接.字符串修改,都是踢走正主后的篡位小人 比如str = &qu