js中Date对象与Math对象常用基础知识

来源:互联网 发布:json数组的遍历 编辑:程序博客网 时间:2024/06/08 05:38

1、js的Date对象

java里面获取当前时间

Date date = new Date();//格式化//DateFormat ddtf = DateFormat.getDateTimeInstance();//System.out.println(ddtf.format(date));

js里date方法

var date = new Date() :js获取当前的时间date.toLocaleString() :格式化 转换成习惯格式getFullYear() :获取当前年份getMonth() :获取当前的月份 // 返回(0~11)getDay() :返回一周中的某一天 //(0-6)周日为0getDate() :返回当前天getHours() :获取当前小时getMinutes() :获取当前的分钟getSeconds() :获取当前秒getTime() :获取从1970年1月1日至今毫秒数 //用来处理缓存(无缓存)

js的Math对象

Math中都是静态方法,可以接使用Math.方法ceil(x) :向上取整floor(x) :向下取整round(x) :四舍五入random() :得到随机数 (0.0~1.0伪随机数)pow(x,y) : x的y次方

Math属性

PI、E、LN2、LN10、LOG2E、LOG10E、SQRT2、SQRT1_2 其值为 1/SQRT2
原创粉丝点击