JavaScript中Date(日期对象),Math对象--学习笔记
Date对象
1.什么是Date对象?
日期对象可以储存任意一个日期,并且可以精确到毫秒数(1/1000 秒)。
语法:var Udate=new Date();
注:初始值为当前时间(当前电脑系统时间)。
2.Date对象常用方法:

3.Date方法实例
var newTime=new Date();//获取当前时间
var millSecond=Date.now();//当前日期转换成的毫秒数
var fullYear=newTime.getFullYear();//获取年份
var year=newTime.getYear();//获取年份
var month=newTime.getMonth();//获取月份 返回0-11 0表示一月 11表示十二月
var week=newTime.getDay();//获取星期几 返回的是0-6的数字,0 表示星期天
var today=newTime.getDate();//获取当天日期
var hours=newTime.getHours();//获取小时数
var minutes=newTime.getMinutes();//获取分钟数
var seconds=newTime.getSeconds();//获取秒数
console.log(newTime);// Wed Feb 04 2015 10:54:17 GMT+0800 (中国标准时间)
console.log(millSecond);//
console.log(fullYear);//
console.log(year);//
console.log(month);//1 表示2月
console.log(week);//3 表示星期三
console.log(today);//4 4号
console.log(hours);//10小时
console.log(minutes);//54分钟
console.log(seconds);//17秒
Math对象
1.什么是Math对象?
Math对象,提供对数据的数学计算。
注意:Math 对象是一个固有的对象,无需创建它,直接把 Math 作为对象使用就可以调用其所有属性和方法。这是它与Date,String对象的区别。
2.Math对象的属性和方法
Math对象属性

Math对象方法

3.Math对象个别方法实例
1):ceil()方法向上取整,返回的是大于或等于x,并且与x最接近的整数。
document.write(Math.ceil(0.8) + "<br />")//
document.write(Math.ceil(6.3) + "<br />")//
document.write(Math.ceil(5) + "<br />")//
document.write(Math.ceil(3.5) + "<br />")//
document.write(Math.ceil(-5.1) + "<br />")//-5
document.write(Math.ceil(-5.9))//-5
2):floor()方法向下取整,返回的是小于或等于x,并且与x最接近的整数。
document.write(Math.floor(0.8) + "<br />")//
document.write(Math.floor(6.3) + "<br />")//
document.write(Math.floor(5) + "<br />")//
document.write(Math.floor(3.5) + "<br />")//
document.write(Math.floor(-5.1) + "<br />")//-6
document.write(Math.floor(-5.9))//-6
3):round() 方法可把一个数字四舍五入为最接近的整数
document.write(Math.round(0.8) + "<br />")//
document.write(Math.round(6.3) + "<br />")//
document.write(Math.round(5) + "<br />")//
document.write(Math.round(3.5) + "<br />")//
document.write(Math.round(-5.1) + "<br />")//-5
document.write(Math.round(-5.9)+"<br />")//-6
4):random() 方法可返回介于 0 ~ 1(大于或等于 0 但小于 1 )之间的一个随机数。
document.write(Math.random());//返回0到1之间的数字 不包括1
document.write(Math.random()*10);//返回0到10之间的数字 不包括10
5):min()方法:返回一组数值中的最小值
document.write(Math.min(2,3,4,6));//2
获取数组中最小值,使用apply()方法:
var values=[3,2,1,8,9,7];
document.write(Math.min.apply(Math,values)+"<br>");//
Math对象作为apply第一个参数,任意数组作为第二参数
6):max()方法:返回一组数值中的最大值
document.write(Math.max(2,3,4,6));//6
获取数组中最小值,使用apply()方法:
var values=[3,2,1,8,9,7];
document.write(Math.max.apply(Math,values)+"<br>");//9
JavaScript中Date(日期对象),Math对象--学习笔记的更多相关文章
- 初识 Javascript.02 -- Date日期、Math对象、数据类型转换、字符串、布尔Boolean、逻辑运算符、if else 、三元表达式、代码调试方法、
Date()对象: Date对象用于处理日期和时间. 1.1 Math对象 ◆Math.ceil() 天花板函数 向上取整 只取整数,不足则进1 ◆Math.floor() 地板函数 ...
- JavaScript中date日期的n种方法
转自博客 https://blog.csdn.net/u013992330/article/details/54318737
- 前端学习 第二弹: JavaScript中的一些函数与对象(1)
前端学习 第二弹: JavaScript中的一些函数与对象(1) 1.apply与call函数 每个函数都包含两个非继承而来的方法:apply()和call(). 他们的用途相同,都是在特定的作用域中 ...
- javascript中Date对象的应用——简易日历的实现
× 目录 [1]效果 [2]HTML [3]CSS[4]JS 前面的话 简易日历作为javascript中Date对象的常见应用,用途较广泛.本文将详细说明简易日历的实现思路 效果演示 HTML说明 ...
- javascript中Date对象的应用
前面的话 简易日历作为javascript中Date对象的常见应用,用途较广泛.本文将详细说明简易日历的实现思路 效果演示 HTML说明 使用type=number的两个input分别作为年和月的输入 ...
- #9.6课堂JS总结#变量作用域 date()对象 math()对象
一.变量的作用域 1.JavaScript的作用域链 首先看下下面这段代码: <script type="text/javascript"> var rain = 1; ...
- JavaScript要点(十七) Math 对象
来源:JavaScript 参考手册 Math 对象 Math 对象用于执行数学任务. Math 对象并不像 Date 和 String 那样是对象的类,因此没有构造函数 Math(). 语法 var ...
- 透过一道面试题来探探JavaScript中执行上下文和变量对象的底
在做面试题之前,我们先搞清楚两个概念 执行上下文(execution context) 变量对象(variable object) 执行上下文 我们都知道JavaScript的作用域一共分三种 全局作 ...
- JavaScript 中的日期和时间
前言 本篇的介绍涵盖以下部分: 1. 时间标准指的是什么?UCT和GMT 的概念.关联和区别? 2. 时间表示标准有哪些? 3. JS 中时间的处理 日期时间标准 日期的标准就不多说了 -- 公元纪年 ...
随机推荐
- background和background-size
今天偶遇一个小问题. 添加logo图片时, 由于不需要重新定位图片位置,就准备偷懒在间歇属性中省略background-position的属性,然而很不幸的是,结果却是酱紫的(谷歌浏览器): 不能加载 ...
- [LeetCode]题解(python):032-Longest Valid Parentheses
题目来源 https://leetcode.com/problems/longest-valid-parentheses/ Given a string containing just the cha ...
- Android笔记:真机调试
参考:android通过USB使用真机调试程序 手机:华为Y511-U00 1.将手机USB调试模式连接到PC(直接用数据线连接到PC一般可以自动切换) 2.连接成功后提示安装驱动,我选择的是自动安装 ...
- ecshop详细的安装教程
ECShop 的安装非常简单.方便,任何一种编码程序的安装方法都是一样的(即 GBK 和 UTF-8 版本的安装方法是一样的) 1.安装前的准备 docs目录下存放有 ECShop 安装说明(inst ...
- Combine String---hdu5727 &&& Zipper(LCS变形)
题目链接:http://poj.org/problem?id=2192 http://acm.split.hdu.edu.cn/showproblem.php?pid=5707 http://acm. ...
- oracle 循环语句
1.基本循环(至少会执行一次) DECLARE I ; BEGIN LOOP --循环开始 DBMS_OUTPUT.PUT_LINE('VALUE:'||I); ; --退出循环条件: I:; --循 ...
- 使用Aspose.Cell控件实现Excel高难度报表的生成(三)
在之前几篇文章中,介绍了关于Apsose.cell这个强大的Excel操作控件的使用,相关文章如下: 使用Aspose.Cell控件实现Excel高难度报表的生成(一) 使用Aspose.Cell控件 ...
- php回调函数
1.array_filter($arr, "odd") <?php $arr = array(1, 2, 3, 4, 5, 6, 7, 8, 9); function odd ...
- Oracle导入中文乱码解决办法
Oracle导入中文乱码解决办法 一.确保各个客户端字符集的编码同服务器字符集编码一致 1- 确定sqlplus字符集编码,如果是windows设置环境变量. 2- 确保Sec ...
- 30天,O2O速成攻略【8.22北京站】
活动概况 时间:2015年8月22日13:30-16:30 地点:车库咖啡(北京市海淀西大街48号鑫鼎宾馆二层) 主办:APICloud.融云.品读者 网址:www.apicloud.com 费用:免 ...