Date.prototype.toDateString()
åºçº¿
广æ³å¯ç¨
èª 2015å¹´7æ èµ·ï¼æ¤ç¹æ§å·²å¨ä¸»æµæµè§å¨ä¸å¾å°æ¯æï¼å¯å¨å¤§å¤æ°è®¾å¤åæµè§å¨çæ¬ä¸æ£å¸¸ä½¿ç¨ã
toDateString() æ¹æ³ä»¥ç¾å¼è±è¯å人类æè¯»çå½¢å¼è¿åä¸ä¸ªæ¥æå¯¹è±¡æ¥æé¨åçå符串ã
å°è¯ä¸ä¸
const event = new Date(1993, 6, 28, 14, 39, 7);
console.log(event.toString());
// Expected output: "Wed Jul 28 1993 14:39:07 GMT+0200 (CEST)"
// Note: your timezone may vary
console.log(event.toDateString());
// Expected output: "Wed Jul 28 1993"
è¯æ³
dateObj.toDateString()
æè¿°
Date 对象å®ä¾å¼ç¨ä¸ä¸ªå
·ä½çæ¶é´ç¹ãè°ç¨ toString æ¹æ³ä¼ä»¥ç¾å¼è±è¯å人类æè¯»çå½¢å¼è¿åæ¥æå¯¹è±¡çæ ¼å¼åå符串ãå¨ SpiderMonkey éï¼è¯¥åç¬¦ä¸²ç±æ¥æé¨åï¼å¹´ææ¥ï¼åå
¶åçæ¶é´é¨åï¼æ¶åç§åæ¶åºï¼ç»æãææ¶éè¦è·åæ¥æé¨åçå符串ï¼è¿å¯ä»¥ç± toDateString æ¹æ³å®æã
The toDateString method is especially useful because compliant engines implementing ECMA-262 may differ in the string obtained from toString for Date objects, as the format is implementation-dependent and simple string slicing approaches may not produce consistent results across multiple engines.
示ä¾
>示ä¾ï¼toDateString æ¹æ³çç®å使ç¨
var d = new Date(1993, 6, 28, 14, 39, 7);
println(d.toString()); // prints Wed Jul 28 1993 14:39:07 GMT-0600 (PDT)
println(d.toDateString()); // prints Wed Jul 28 1993
è§è
| è§è |
|---|
| ECMAScript® 2027 Language Specification> # sec-date.prototype.todatestring> |