Date 对象方法

来源:互联网 发布:西方文化渗透 知乎 编辑:程序博客网 时间:2024/05/22 17:22
<!DOCTYPE html><html>    <head>        <meta charset="UTF-8">        <title>Date 对象方法</title>    </head>    <body>    </body>    <script type="text/javascript">        //getDate() 从 Date 对象返回一个月中的某一天 (1 ~ 31)。        var d = new Date();        document.write(d.getDate());//3        document.write("</br>");        //getDay()  从 Date 对象返回一周中的某一天 (0 ~ 6)。        document.write(d.getDay());//1        document.write("</br>");        //getFullYear() 从 Date 对象以四位数字返回年份。        document.write(d.getFullYear());//2017        document.write("</br>");        //getHours()    返回 Date 对象的小时 (0 ~ 23)。        document.write(d.getHours());//9        document.write("</br>");        //getMilliseconds() 返回 Date 对象的毫秒(0 ~ 999)。        document.write(d.getMilliseconds());//689        document.write("</br>");        //getMinutes()  返回 Date 对象的分钟 (0 ~ 59)。        document.write(d.getMinutes());//23        document.write("</br>");        //getMonth()    从 Date 对象返回月份 (0 ~ 11)。        document.write(d.getMonth());//6        document.write("</br>");        //getSeconds()  返回 Date 对象的秒数 (0 ~ 59)。        document.write(d.getSeconds());//17        document.write("</br>");        //getTime() 返回 1970 年 1 月 1 日至今的毫秒数。        document.write(d.getTime());//1499045088872        document.write("</br>");        //getTimezoneOffset()   返回本地时间与格林威治标准时间 (GMT) 的分钟差。        document.write(d.getTimezoneOffset());//-480        document.write("</br>");        //getUTCDate()  根据世界时从 Date 对象返回月中的一天 (1 ~ 31)。        document.write(d.getUTCDate());//3        document.write("</br>");        //getUTCDay()   根据世界时从 Date 对象返回周中的一天 (0 ~ 6)。        document.write(d.getUTCDay());//1        document.write("</br>");        //getUTCFullYear()  根据世界时从 Date 对象返回四位数的年份。        document.write(d.getUTCFullYear());//2017        document.write("</br>");        //getUTCHours() 根据世界时返回 Date 对象的小时 (0 ~ 23)。        document.write(d.getUTCHours());//1        document.write("</br>");        //getUTCMilliseconds()  根据世界时返回 Date 对象的毫秒(0 ~ 999)。        document.write(d.getUTCMilliseconds());//199        document.write("</br>");        //getUTCMinutes()   根据世界时返回 Date 对象的分钟 (0 ~ 59)。        document.write(d.getUTCMinutes());//29        document.write("</br>");        //getUTCMonth() 根据世界时从 Date 对象返回月份 (0 ~ 11)。        document.write(d.getUTCMonth());//6        document.write("</br>");        //getUTCSeconds()   根据世界时返回 Date 对象的秒钟 (0 ~ 59)。        document.write(d.getUTCSeconds());//56        document.write("</br>");        //parse()   返回1970年1月1日午夜到指定日期(字符串)的毫秒数。        document.write(Date.parse("March 21, 2012"));//1332259200000        document.write("</br>");        //setDate() 设置 Date 对象中月的某一天 (1 ~ 31)。        d.setDate(15);        document.write(d);//Sat Jul 15 2017 09:47:28 GMT+0800 (中国标准时间)        document.write("</br>");        //setFullYear() 设置 Date 对象中的年份(四位数字)。        d.setFullYear(2020);        document.write(d);//Wed Jul 15 2020 09:48:17 GMT+0800 (中国标准时间)        document.write("</br>");        //setHours()    设置 Date 对象中的小时 (0 ~ 23)。        d.setHours(15);        document.write(d);//Wed Jul 15 2020 15:48:58 GMT+0800 (中国标准时间)        document.write("</br>");        //setMilliseconds() 设置 Date 对象中的毫秒 (0 ~ 999)。        var d = new Date();        d.setMilliseconds(192);        var n = d.getMilliseconds();        document.write(n);//192        document.write("</br>");        //setMinutes()  设置 Date 对象中的分钟 (0 ~ 59)。        d.setMinutes(17);        document.write(d);//Mon Jul 03 2017 09:17:37 GMT+0800 (中国标准时间)        document.write("</br>");        //setMonth()    设置 Date 对象中月份 (0 ~ 11)。        d.setMonth(4);        document.write(d);//Wed May 03 2017 09:17:20 GMT+0800 (中国标准时间)        document.write("</br>");        //setSeconds()  设置 Date 对象中的秒钟 (0 ~ 59)。        d.setSeconds(35);        document.write(d);//Wed May 03 2017 09:17:35 GMT+0800 (中国标准时间)        document.write("</br>");        //setTime() setTime() 方法以毫秒设置 Date 对象。        d.setTime(1332403882588);        document.write(d);//Thu Mar 22 2012 16:11:22 GMT+0800 (中国标准时间)        document.write("</br>");        //setUTCDate()  根据世界时设置 Date 对象中月份的一天 (1 ~ 31)。        d.setUTCDate(15);        document.write(d);//Thu Mar 15 2012 16:11:22 GMT+0800 (中国标准时间)        document.write("</br>");        //setUTCFullYear()  根据世界时设置 Date 对象中的年份(四位数字)。        d.setUTCFullYear(1992);        document.write(d);//Sun Mar 22 1992 16:11:22 GMT+0800 (中国标准时间)        document.write("</br>");        //setUTCHours() 根据世界时设置 Date 对象中的小时 (0 ~ 23)。        d.setUTCHours(15);        document.write(d);//Sun Mar 22 1992 23:11:22 GMT+0800 (中国标准时间)        document.write("</br>");        //setUTCMilliseconds()  根据世界时设置 Date 对象中的毫秒 (0 ~ 999)。        var d = new Date();        d.setUTCMilliseconds(192);        var n = d.getUTCMilliseconds();        document.write(n);//192        document.write("</br>");        //setUTCMinutes()   根据世界时设置 Date 对象中的分钟 (0 ~ 59)。        d.setUTCMinutes(17);        document.write(d);//Mon Jul 03 2017 10:17:41 GMT+0800 (中国标准时间)        document.write("</br>");        //setUTCMonth() 根据世界时设置 Date 对象中的月份 (0 ~ 11)。        d.setUTCMonth(4);        document.write(d);//Wed May 03 2017 10:17:50 GMT+0800 (中国标准时间)        document.write("</br>");        //setUTCSeconds()   setUTCSeconds() 方法用于根据世界时 (UTC) 设置指定时间的秒字段。        d.setUTCSeconds(35);        document.write(d);//Wed May 03 2017 10:17:35 GMT+0800 (中国标准时间)        document.write("</br>");        //toDateString()    把 Date 对象的日期部分转换为字符串。        var d = new Date();        var n = d.toDateString();        document.write(n);//Mon Jul 03 2017        document.write("</br>");        //toISOString() 使用 ISO 标准返回字符串的日期格式。        var d=new Date();        var n=d.toISOString();        document.write(n);//2017-07-03T02:14:09.530Z        document.write("</br>");        //toJSON()  以 JSON 数据格式返回日期字符串。        var n=d.toJSON();        document.write(n);//2017-07-03T02:14:09.530Z        document.write("</br>");        //toLocaleDateString()  根据本地时间格式,把 Date 对象的日期部分转换为字符串。        var n=d.toLocaleDateString();        document.write(n);//2017-07-03T02:16:24.333Z        document.write("</br>");        //toLocaleTimeString()  根据本地时间格式,把 Date 对象的时间部分转换为字符串。        var n=d.toLocaleTimeString();        document.write(n);//上午10:17:35        document.write("</br>");        //toLocaleString()  据本地时间格式,把 Date 对象转换为字符串。        var n=d.toLocaleString();        document.write(n);//2017/7/3 上午10:18:38        document.write("</br>");        //toString()    把 Date 对象转换为字符串。        var n=d.toString();        document.write(n);//Mon Jul 03 2017 10:19:06 GMT+0800 (中国标准时间)        document.write("</br>");        //toTimeString()    把 Date 对象的时间部分转换为字符串。        var n=d.toTimeString();        document.write(n);//10:20:08 GMT+0800 (中国标准时间)        document.write("</br>");        //toUTCString() 根据世界时,把 Date 对象转换为字符串。        var n=d.toUTCString();        document.write(n);//Mon, 03 Jul 2017 02:20:44 GMT        document.write("</br>");        //UTC() 根据世界时返回 1970 年 1 月 1 日 到指定日期的毫秒数。        var d=Date.UTC(2012,02,30);        document.write(d);//1333065600000        document.write("</br>");        //valueOf() 返回 Date 对象的原始值。        var n=d.valueOf();        document.write(n);//1333065600000        document.write("</br>");    </script></html>