Date 对象方法


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

你可能感兴趣的:(javascript)