JS date format conversion method: 1. Use "new Date()" to get the current date; 2. Use getFullYear() to get the year corresponding to the date, use "getMonth() 1" to get the corresponding month, use getDate() gets the date of the corresponding month.
The operating environment of this tutorial: Windows 7 system, JavaScript version 1.8.5, Dell G3 computer.
1. Get the current date.
<script type="text/javascript"> var d = new Date(); alert("当前日期: :" + d); </script>
This date is not suitable for direct use and needs to be converted into an intuitive time.
2. Modified code:
var d = new Date(); var d2 = d.getFullYear() + "年"+ (d.getMonth() + 1) +"月"+ d.getDate() +"日"; alert("当前日期: :" + d2);
<img src="https://img.php.cn/upload/image/353/231/963/1617871135393328.png" title="1617871135393328.png" alt="How to convert javascript date format to year, month and day">
javascript video tutorial]
The above is the detailed content of How to convert javascript date format to year, month and day. For more information, please follow other related articles on the PHP Chinese website!