This article mainly introduces how to get the time of js and convert the string and timestamp. If you need a friend, you can refer to the following nonsense and directly go to the code.
The Code is as follows:
// Obtain the current time:
Var myDate = new Date (); // current time
Var year = myDate. getFullYear (); // current year
Var month = myDate. getMonth () + 1; // the current month
Var day = myDate. getDate (); // current day
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
Var oneDay = 1000*60*60*24;
// Obtain the date of the last week
Var lastDate = new Date (myDate-oneDay * 6 );
Var lastYear = lastDate. getFullYear ();
Var lastMonth = lastDate. getMonth () + 1;
Var lastDay = lastDate. getDate ();
// Obtain the last day of the current month
Var day = new Date (year, month, 0 );
Var lastdate = day. getDate (); // the last day of the current month
// Obtain the date of the last N months
Var lastDate = new Date (myDate-oneDay * myDate. getDate ());
LastDate = new Date (lastDate-N * oneDay * (lastDate. getDate ()-1 ));
Var lastYear = lastDate. getFullYear ();
Var lastMonth = lastDate. getMonth () + 1;
Var lastDay = lastDate. getDate ();
// Convert string to Timestamp
Var date = "2014-12-06 ";
Date = new Date (Date. parse (date. replace (/-/g ,"/")));
Date = date. getTime ();