下面是一个例子 日期原型属性 .
null
- 例子:
javascript
<script> var birthday = new Date( 'June 21, 2018 16:44:23' ); var date1 = birthday.getDate(); var day1 = birthday.getDay(); var year1 = birthday.getFullYear(); var hour1 = birthday.getHours(); var ms1 = birthday.getMilliseconds(); var m1 = birthday.getMinutes(); var mth1 = birthday.getMonth(); var time1 = birthday.getTime(); var s1 = birthday.getSeconds(); var offset = birthday.getTimezoneOffset(); var date2 = birthday.getUTCDate(); var day2 = birthday.getUTCDay(); var year2 = birthday.getUTCFullYear(); var hour2 = birthday.getUTCHours(); var ms2 = birthday.getUTCMilliseconds(); var um1 = birthday.getUTCMinutes(); var umth = birthday.getUTCMonth(); var us = birthday.getUTCSeconds(); document.write(date1 +"<br>"); document.write(day1 +"<br>"); document.write(year1 +"<br>"); document.write(hour1 +"<br>"); document.write(ms1 +"<br>"); document.write(m1 +"<br>"); document.write(mth1 +"<br>"); document.write(time1 +"<br>"); document.write(s1 +"<br>"); document.write(offset +"<br>"); document.write(date2 +"<br>"); document.write(day2 +"<br>"); document.write(year2 +"<br>"); document.write(hour2 +"<br>"); document.write(ms2 +"<br>"); document.write(um1 +"<br>"); document.write(umth +"<br>"); document.write(us); </script> |
- 输出:
2142018160445152957966300023-330214201811014523
注: 这个 日期原型 属性表示日期构造函数的原型。 它有以下方法:
- getDate() : 此方法将根据本地时间返回指定日期的月份日期。
- getDay() : 此方法将根据当地时间返回指定日期的星期几(0表示星期天,6表示星期六)。
- getFullYear() : 它根据当地时间返回指定日期的年份。
- getHours() : 它根据当地时间返回指定日期的小时数(0-23)。
- Get毫秒: 它根据本地时间返回指定日期的毫秒(0-999)。
- getMinutes() : 它根据当地时间返回指定日期的分钟数(0-59)。
- getMonth() : 它根据当地时间返回指定日期的月份(0-11)。
- getSeconds() : 它根据当地时间返回指定日期的秒数(0-59)。
- getTime(): 它返回自1970年1月1日00:00:00 UTC以来经过的毫秒数。这对时间是负面的 在给定的时间之前。
- getTimezoneOffset() : 它返回当前位置的时区偏移量(以分钟为单位)。
- getUTCDate() : 它根据世界时间返回指定日期的月份日期(1-31)。
- getUTCDay() : 它根据世界时间返回指定日期的星期几(0-6)。
- getUTCFullYear() : 它根据世界时间返回指定日期的年份。
- getUTCHours() : 它根据世界时间返回指定日期的小时数(0-23)。
- getUTCMilliseconds() : 它根据世界时返回指定日期的毫秒(0-999)。
- getUTCMinutes() : 它根据世界时间返回指定日期的分钟数(0-59)。
- getUTCMonth() : 它根据世界时间返回指定日期的月份(0-11)。
- getUTCSeconds() : 它根据世界时返回指定日期的秒数(0-59)。
它还有一些其他方法可用于将日期转换为不同的格式:
- toDateString() : 以可读字符串的形式返回日期的“日期”部分。
- TogmString(): 返回一个字符串,该字符串表示基于GMT(UT)时区的日期。
- toLocaleFormat(): 使用格式字符串将日期转换为字符串。
- toLocalestring() : 返回一个字符串,其中包含此日期的地区敏感表示形式。
- toString() : 返回表示指定日期对象的字符串。
- toTimeString() : 以可读字符串的形式返回日期的“时间”部分。
- 价值 : 返回日期对象的基本值。
支持的浏览器: 支持的浏览器 JavaScript日期原型属性 以下列出了:
- 谷歌浏览器
- Internet Explorer
- Mozilla Firefox
- 歌剧
- 游猎
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END