How to get the current time using js

php中世界最好的语言
Release: 2018-06-04 10:48:55
Original
1835 people have browsed it

This time I will show you how to use js to get the current time, and what are theprecautions for using js to get the current time. The following is a practical case, let's take a look.

Date object

setDate(): Set a certain day of the month.
getFullYear(): Returns a four-digit number representing the year.
getMonth(): Represents the month field, using local time. An integer between 0-11.

getDate(): Get the day of the month.

function GetDateStr(AddDayCount) { var dd = new Date(); dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期 var y = dd.getFullYear(); var ddM = dd.getMonth(); if(ddM.toString().length==1){ var m = dd.getMonth()+1; m = '0'+m;//格式 == 02 }else{ var m = dd.getMonth()+1;//格式 == 10 } var d = dd.getDate(); return y+"-"+m+"-"+d; }
Copy after login

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to the php Chinese website

Otherrelated articles!

Recommended reading:

Use JS to perform encryption and decryption operations

##How to make a node.js interface


The above is the detailed content of How to get the current time using js. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!