JS初识(着重讲解Date函数)

查看类型:typeof()

转换为int类型:parseInt()

isNaN() 函数用于检查其参数是否是非数字值。

NaN,是Not a Number的缩写。一种计算机用语。NaN 用于处理计算中出现的错误情况,比如 0.0 除以 0.0 或者求负数的平方根。在Matlab中,NaN是一个预定义的常量,表示“不明确的数值结果”。还有Inf表示“无穷大”,pi表示常数π等等。

Math.floor(x) -- 返回小于等于数字参数的最大整数,对数字进行下舍入.

例如:

document.write(Math.floor(5.99));
document.write(Math.floor(-5.99));
document.write(Math.floor(1.01));
document.write(Math.floor(-1.01));

//结果

5
-6
1
-2

得到现在的时间

var now = new Date();//现在的时间

getTime() 方法可返回距 1970 年 1 月 1 日之间的毫秒数。

getDate() 从 Date 对象返回一个月中的某一天 (1 ~ 31)。
getDay() 从 Date 对象返回一周中的某一天 (0 ~ 6)。
getMonth() 从 Date 对象返回月份 (0 ~ 11)。
getFullYear() 从 Date 对象以四位数字返回年份。
getYear() 请使用 getFullYear() 方法代替。
getHours() 返回 Date 对象的小时 (0 ~ 23)。
getMinutes() 返回 Date 对象的分钟 (0 ~ 59)。
getSeconds() 返回 Date 对象的秒数 (0 ~ 59)。
getMilliseconds() 返回 Date 对象的毫秒(0 ~ 999)。

创建Date()的形式如下:

   new Date("month dd,yyyy hh:mm:ss");
   new Date("month dd,yyyy");
   new Date(yyyy,mth,dd,hh,mm,ss);
   new Date(yyyy,mth,dd);
   new Date(ms);
原文地址:https://www.cnblogs.com/llcdbk/p/4071615.html