Home>Article>Web Front-end> How to output the day of the week in JavaScript
Method: 1. Define the "Array("Day", "One", "Two", "Three", "Four", "Five", "Six")" array; 2. Use getDay( ) method to obtain the number representing the day of the week; 3. Use the number as a subscript to obtain the value in the array; 4. Output through "document.write".
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
How to output the week in JavaScript:
In the js tag, use the getDay() method to get today’s week code from the Date object . Then the Chinese name of the week is obtained by encoding the week in the array.
The getDay() method can return the number of a certain day of the week (0~6). Sunday is 0, Monday is 1, and so on.
JavaScript's Date object is used to process dates and times.
The code is as follows:
new Date().getDay()
Document
Output result:
The above example is in the form of a pop-up window, of course it can also be through a document. Write direct output:
#For more programming-related knowledge, please visit:Programming Video! !
The above is the detailed content of How to output the day of the week in JavaScript. For more information, please follow other related articles on the PHP Chinese website!