JavaScript Date function

Source: Internet
Author: User

Gets the date of the day before the current date

 ? ?var MyDate = new Date( ); ?//获取昨天的日期 ? ?var yesterday = myDate.getTime()-1000*60*60*24; ? ?var date = new Date(); ? ?date.setTime(yesterday);
Get current time
date.getYear+1900=date.getFullYear()date.getMonth();//获取系统月份,由于月份是从0开始计算,所以加1date.getDate();//获取系统日date.getHours(); //获取系统时date.getMinutes(); //获取系统分date.getSeconds() ? ?//获取系统秒
Get current time
var now = new Date();获取当前时间后一天或后面一个小时的时间var now ?= new Date();now = now.setDate( now.getDate( )+1 );hour = now.setHour(now.getHours( )+1);
Gets the current timestamp (in s)
var timestamp = Date.parse(new Date())console.log(timestamp);1442825058000?function toDDMMYYYY(date){ var d = new Date(date.getTime()); var dd = d.getDate()<10 ? "0":d.getDate:d:getDate().toString(); var mmm = mths[d.getMonth()]; var yyyy = d.getFullYear().toString(); //2011 return dd+mmm+yyyy;}?function toDDMMYYYY(date){ var d = toDDMMYYYY(date); return d.substring(0,5)+d.substring(7,9);}

Date conversion to String type

JavaScript Date function

Related Article

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.