Date
返回本机当前时间戳 Date.now()
API
| 方 法 | 说 明 |
|---|
| toDateString() | 显示日期中的周几、月、日、年(格式特定于实现) |
| toTimeString() | 显示日期中的时、分、秒和时区(格式特定于实现) |
| toLocaleDateString() | 显示日期中的周几、月、日、年(格式特定于实现和地区) |
| toLocaleTimeString() | 显示日期中的时、分、秒(格式特定于实现和地区) |
| toUTCString() | 显示完整的 UTC 日期(格式特定于实现) |
| getTime() | 返回日期的毫秒表示;与 valueOf()相同 |
| setTime(milliseconds) | 设置日期的毫秒表示,从而修改整个日期 |
| getFullYear() | 返回 4 位数年(即 2019 而不是 19) |
| getUTCFullYear() | 返回 UTC 日期的 4 位数年 |
| setFullYear(year) | 设置日期的年(year 必须是 4 位数) |
| setUTCFullYear(year) | 设置 UTC 日期的年(year 必须是 4 位数) |
| getMonth() | 返回日期的月(0 表示 1 月,11 表示 12 月) |
| getUTCMonth() | 返回 UTC 日期的月(0 表示 1 月,11 表示 12 月) |
| setMonth(month) | 设置日期的月(month 为大于 0 的数值,大于 11 加年) |
| setUTCMonth(month) | 设置 UTC 日期的月(month 为大于 0 的数值,大于 11 加年) |
| getDate() | 返回日期中的日(1~31) |
| getUTCDate() | 返回 UTC 日期中的日(1~31) |
| setDate(date) | 设置日期中的日(如果 date 大于该月天数,则加月) |
| setUTCDate(date) | 设置 UTC 日期中的日(如果 date 大于该月天数,则加月) |
| getDay() | 返回日期中表示周几的数值(0 表示周日,6 表示周六) |
| getUTCDay() | 返回 UTC 日期中表示周几的数值(0 表示周日,6 表示周六) |
| getHours() | 返回日期中的时(0~23) |
| getUTCHours() | 返回 UTC 日期中的时(0~23) |
| setHours(hours) | 设置日期中的时(如果 hours 大于 23,则加日) |
| setUTCHours(hours) | 设置 UTC 日期中的时(如果 hours 大于 23,则加日) |
| getMinutes() | 返回日期中的分(0~59) |
| getUTCMinutes() | 返回 UTC 日期中的分(0~59) |
| setMinutes(minutes) | 设置日期中的分(如果 minutes 大于 59,则加时) |
| setUTCMinutes(minutes) | 设置 UTC 日期中的分(如果 minutes 大于 59,则加时) |
| getSeconds() | 返回日期中的秒(0~59) |
| getUTCSeconds() | 返回 UTC 日期中的秒(0~59) |
| setSeconds(seconds) | 设置日期中的秒(如果 seconds 大于 59,则加分) |
| setUTCSeconds(seconds) | 设置 UTC 日期中的秒(如果 seconds 大于 59,则加分) |
| getMilliseconds() | 返回日期中的毫秒 |
| getUTCMilliseconds() | 返回 UTC 日期中的毫秒 |
| setMilliseconds(milliseconds) | 设置日期中的毫秒 |
| setUTCMilliseconds(milliseconds) | 设置 UTC 日期中的毫秒 |
| getTimezoneOffset() | 返回以分钟计的 UTC 与本地时区的偏移量 - 如美国 EST 即“东部标准时间”返回 300,进入夏令时的地区可能有所差异 |
String
API
| 方 法 | 说 明 |
|---|
| valueOf() | 返回特定对象的原始值重写 Object.prototype.valueOf 方法 |
| toString() | 返回用字符串表示的特定对象重写 Object.prototype.toString 方法 |
| toLocaleLowerCase() | 根据当前区域设置,将符串中的字符转换成小写对于大多数语言来说,toLowerCase的返回值是一致的 |
| toLocaleUpperCase() | 根据当前区域设置,将字符串中的字符转换成大写,对于大多数语言来说,toUpperCase的返回值是一致的 |
| toLowerCase() | 将字符串转换成小写并返回 |
| toUpperCase() | 将字符串转换成大写并返回 |
| trim() | 从字符串的开始和结尾去除空格参照部分 ECMAScript 5 标准 |
| trimStart() | 从字符串的左侧去除空格 |
| trimEnd() | 从字符串的右侧去除空格 |
| concat() | 连接两个字符串文本,并返回一个新的字符串 |
| slice() | 摘取一个字符串区域,返回一个新的字符串 |
| split() | 通过分离字符串成字串,将字符串对象分割成字符串数组 |
| match() | 使用正则表达式与字符串相比较 |
| search() | 对正则表达式和指定字符串进行匹配搜索,返回第一个出现的匹配项的下标 |
| localeCompare() | 返回一个数字表示是否引用字符串在排序中位于比较字符串的前面,后面,或者二者相同 |
| repeat() | 返回指定重复次数的由元素组成的字符串对象 |
| padEnd() | 在当前字符串尾部填充指定的字符串, 直到达到指定的长度 返回一个新的字符串 |
| padStart() | 在当前字符串头部填充指定的字符串, 直到达到指定的长度 返回一个新的字符串 |
| replace() | 被用来在正则表达式和字符串直接比较,然后用新的子串来替换被匹配的子串 |
| indexOf() | 从字符串对象中返回首个被发现的给定值的索引值,如果没有找到则返回-1 |
| lastIndexOf() | 从字符串对象中返回最后一个被发现的给定值的索引值,如果没有找到则返回-1 |
| includes() | 判断一个字符串里是否包含其他字符串 |
| startsWith() | 判断字符串的起始位置是否匹配其他字符串中的字符 |
| endsWith() | 判断一个字符串的是否以给定字符串结尾,结果返回布尔值 |
| substr() | 通过指定字符数返回在指定位置开始的字符串中的字符 |
| substring() | 返回在字符串中指定两个下标之间的字符 |
| charAt() | 返回特定位置的字符 |
| charCodeAt() | 返回表示给定索引的字符的Unicode的值 |
| codePointAt() | 返回使用UTF-16编码的给定位置的值的非负整数 |
| normalize() | 返回调用字符串值的Unicode标准化形式 |
| anchor() | 返回 <a name="name"> |
| link() | 返回 <a href="url"> |
国际化 Intl
API
| 方 法 | 说 明 |
|---|
| Intl.Collator | collators的构造函数,用于启用对语言敏感的字符串比较的对象 |
| Intl.ListFormat | 语言相关的列表格式化构造器 |
| Intl.PluralRules | 用于启用多种敏感格式和多种语言语言规则的对象的构造函数 |
| Intl.NumberFormat | 根据语言来格式化数字的对象的构造函数 |
| Intl.DateTimeFormat | 根据语言来格式化日期和时间的对象的构造器 |
| Intl.RelativeTimeFormat | 根据语言格式化相对时间格式 |
var number = 123456.789;
console.log(new Intl.NumberFormat('de-DE').format(number));
console.log(new Intl.NumberFormat('ar-EG').format(number));
console.log(new Intl.NumberFormat('en-IN').format(number));
console.log(new Intl.NumberFormat('zh-Hans-CN-u-nu-hanidec').format(number));
console.log(new Intl.NumberFormat(['ban', 'id']).format(number));
console.log(new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(number));
console.log(new Intl.NumberFormat('ja-JP', { style: 'currency', currency: 'JPY' }).format(number));
console.log(new Intl.NumberFormat('en-IN', { maximumSignificantDigits: 3 }).format(number));
console.log(new Intl.NumberFormat('en-US', { notation: "scientific" }).format(987654321));
console.log(new Intl.NumberFormat('pt-PT', { notation: "scientific" }).format(987654321));
console.log(new Intl.NumberFormat('en-GB', { notation: "engineering" }).format(987654321));
console.log(new Intl.NumberFormat('de', { notation: "engineering" }).format(987654321));
console.log(new Intl.NumberFormat('zh-CN', { notation: "compact" }).format(987654321));
console.log(new Intl.NumberFormat('fr', { notation: "compact" , compactDisplay: "long" }).format(987654321));
console.log(new Intl.NumberFormat('en-GB', { notation: "compact" , compactDisplay: "short" }).format(987654321));
const date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
console.log(new Intl.DateTimeFormat('en-US').format(date));
console.log(new Intl.DateTimeFormat('en-GB').format(date));
console.log(new Intl.DateTimeFormat(['ban', 'id']).format(date));
const rtf = new Intl.RelativeTimeFormat("en",{
localeMatcher: "bestfit",
numeric: "always",
style: "long",
});
rtf.format(-1,"day");
rtf.format(1,"day");
内置对象函数
API
| 方 法 | 说 明 |
|---|
| eval() | 将传入的字符串当做 JavaScript 代码进行执 |
| isFinite() | 判断被传入的参数值是否为一个有限数值 |
| isNaN() | 判断被传入的参数值是否为NaN |
| parseFloat() | 解析一个参数并返回一个浮点数 |
| parseInt() | 解析一个字符串并返回指定基数的十进制整数 |
| encodeURI() | 对 URI 进行编码 |
| decodeURI() | 解码由 encodeURI 创建或其它流程得到的统一资源标识符 |
| encodeURIComponent() | 对 URI 组件进行编码 |
| decodeURIComponent() | 解码由 encodeURIComponent 创建或其它流程得到的统一资源标识符 |
其他
document.write("\uFB00")
文档
MDN - JavaScript 参考
语言代码表