js獲取資料 js日期函式總結

2021-10-01 16:00:13 字數 1395 閱讀 3337

1.

通過名字獲取:document

.getelementbyname

(「name」).

value;2.

通過id獲取:

document

.getelementbyid

(「id」).

value;3.

通過類獲取:document

.getelementsbyclassname

(「class」).

value;4.

獲取文件中id

=「queryselector」的值:document

.queryselector

("#queryselector").

value;

var

mydate

=new

date()

;mydate

.getyear()

;//獲取當前年份(2

位)mydate

.getfullyear()

;//獲取完整的年份(4

位,1970

-???

)mydate

.getmonth()

;//獲取當前月份(0

-11,0

代表1月)

mydate

.getdate()

;//獲取當前日(1

-31)mydate

.getday()

;//獲取當前星期x(0

-6,0

代表星期天

)mydate

.gettime()

;//獲取當前時間(從

1970.1

.1開始的毫秒數

)mydate

.gethours()

;//獲取當前小時數(0

-23)mydate

.getminutes()

;//獲取當前分鐘數(0

-59)mydate

.getseconds()

;//獲取當前秒數(0

-59)mydate

.getmilliseconds()

;//獲取當前毫秒數(0

-999

)mydate

.tolocaledatestring()

;//獲取當前日期

varmytime

=mydate

.tolocaletimestring()

;//獲取當前時間

mydate

.tolocalestring()

;//獲取日期與時間

獲取當前時間
function getnowtime()

JS 獲取日期

function getnowformatdate if strdate 0 strdate 9 var currentdate date.getfullyear seperator1 month seperator1 strdate date.gethours seperator2 date.ge...

JS日期獲取

var mydate new date mydate.getyear 獲取當前年份 2位 mydate.getfullyear 獲取完整的年份 4位,1970 mydate.getmonth 獲取當前月份 0 11,0代表1月 mydate.getdate 獲取當前日 1 31 mydate.get...

js 日期函式用法總結

1 建立date物件,用於處理日期和時間 var date new date date物件會把當前日期和時間儲存為初始值。還可以設定其它引數初始化 date物件 new date month dd,yyyy hh mm ss new date month dd,yyyy newdate yyyy,m...