JS Convert date string to timestamp star small stack

Source: Internet
Author: User

Get current time:
var mydate = new Date ();//Current time
var year = Mydate.getfullyear ();//Current years
var month = Mydate.getmonth () + 1;//Current Month
var day = Mydate.getdate ();//Current date
Mydate.getyear (); Get Current year (2-bit)
Mydate.getfullyear (); Get the full year (4-bit, 1970-????)
Mydate.getmonth (); Get the current month (0-11, 0 for January)
Mydate.getdate (); Get current day (1-31)
Mydate.getday (); Get Current week x (0-6, 0 for Sunday)
Mydate.gettime (); Gets the current time (the number of milliseconds since 1970.1.1)
Mydate.gethours (); Get current number of hours (0-23)
Mydate.getminutes (); Gets the current number of minutes (0-59)
Mydate.getseconds (); Gets the current number of seconds (0-59)
Mydate.getmilliseconds (); Gets the current number of milliseconds (0-999)
Mydate.tolocaledatestring (); Get Current date
var mytime=mydate.tolocaletimestring (); Get current time
Mydate.tolocalestring (); Get Date and time
var oneday = 1000 * 60 * 60 * 24;
Get 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 ();
Get 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
Gets 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 ();
string conversion to Timestamp
var date= "2014-05-08 00:22:11";
Date = new Date (Date.parse (Date.replace (/-/g, "/")));
Date = Date.gettime ();

JS Convert date string to timestamp star small stack

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.