Summary of Javascript time operations and summary of javascript operations
Source: http://www.ido321.com/847.html
A timer is required for the project. The effect is as follows:
Js Code
1:/* Get the current time */
2: function getCurrentDate()
3: {
4: var timeStr = '';
5: var curDate = new Date();
6: var curMonth = curDate. getMonth () + 1; // obtain the current month (0-11, 0 represents January)
7: var curDay = curDate. getDate (); // obtain the current day (1-31)
8: var curWeekDay = curDate. getDay (); // obtain X of the current week (0-6, 0 indicates Sunday)
9: var curHour = curDate. getHours (); // obtain the current hour (0-23)
10: var curMinute = curDate. getMinutes (); // obtain the current number of minutes (0-59)
11: var curSec = curDate. getSeconds (); // obtain the current number of seconds (0-59)
12: timeStr = curMonth + 'month' + curDay + 'day Week ';
13: switch(curWeekDay)
14: {
15: case 0: timeStr + = 'day'; break;
16: case 1: timeStr + = '1'; break;
17: case 2: timeStr + = '2'; break;
18: case 3: timeStr + = '3'; break;
19: case 4: timeStr + = '4'; break;
20: case 5: timeStr + = '5'; break;
21: case 6: timeStr + = '6'; break;
22: }
23: if(curHour < 10)
24: {
25: if(curMinute < 10)
26: {
27: if(curSec < 10)
28: {
29: timeStr += ' 0'+curHour+':0'+curMinute+':0'+curSec;
30: }
31: else
32: {
33: timeStr += ' 0'+curHour+':0'+curMinute+':'+curSec;
34: }
35: }
36: else
37: {
38: if(curSec < 10)
39: {
40: timeStr += ' 0'+curHour+':'+curMinute+':0'+curSec;
41: }
42: else
43: {
44: timeStr += ' 0'+curHour+':'+curMinute+':'+curSec;
45: }
46: }
47: }
48: else
49: {
50: if(curMinute < 10)
51: {
52: if(curSec < 10)
53: {
54: timeStr += ' '+curHour+':0'+curMinute+':0'+curSec;
55: }
56: else
57: {
58: timeStr += ' '+curHour+':0'+curMinute+':'+curSec;
59: }
60: }
61: else
62: {
63: if(curSec < 10)
64: {
65: timeStr += ' '+curHour+':'+curMinute+':0'+curSec;
66: }
67: else
68: {
69: timeStr += ' '+curHour+':'+curMinute+':'+curSec;
70: }
71: }
72: }
73: $("#time").text(timeStr);
74: }
Then use this function.
Finally, we will summarize some functions of the Javascript Date:
Var myDate = new Date ();
MyDate. getYear (); // obtain the current year (2 digits)
MyDate. getFullYear (); // obtain the complete year (4 bits, 1970 -????)
MyDate. getMonth (); // obtain the current month (0-11, 0 represents January)
MyDate. getDate (); // obtain the current day (1-31)
MyDate. getDay (); // obtain X of the current week (0-6, 0 indicates Sunday)
MyDate. getTime (); // obtain the current time (milliseconds starting from 1970.1.1)
MyDate. getHours (); // obtain the current hour (0-23)
MyDate. getMinutes (); // obtain the current number of minutes (0-59)
MyDate. getSeconds (); // obtain the current number of seconds (0-59)
MyDate. getMilliseconds (); // obtain the current number of milliseconds (0-999)
MyDate. toLocaleDateString (); // obtain the current date
Var mytime = myDate. toLocaleTimeString (); // obtain the current time
MyDate. toLocaleString (); // obtain the date and time
How long does it take to learn javascript?
If you have other language basics, it is best not to have more than one week; if you have no basic language, it is best not to have more than two weeks;
In general, learning Javascript is mainly used to obtain form values, verify data, submit forms, dynamically operate tables, and exchange data without any additional concerns. As mentioned above, I am familiar with DOM, ajax; (document prompt)
Developers learn this mainly to lay the foundation for learning the relevant frameworks in the future. It is said that if you can write a calendar control, it means that JS has learned very well.
Focus on looking at the development direction. If it is the front-end, DIV, CSS, and JS, this needs to be further explored;
In other aspects, it is generally possible.
For beginners, let's start with several basic examples, such as how to obtain the value of a form...
How long does it take to learn javascript?
Go to w3school to learn html dom and javascript. The lecture is very simple. After learning it, you can do form verification and some simple effects. You can learn it in at least one week. AJAX recommendations, this entry is also very simple. The warning box is exclusive to IE. It will be okay if Firefox is used, or if you put the webpage in IDE, it will not be displayed.