gpt4 book ai didi

javascript - JS - 如何获取并计算当前日期

转载 作者:行者123 更新时间:2023-11-28 13:36:02 24 4
gpt4 key购买 nike

抱歉,显示当前日期的最快方式是什么?

 2014-01-18 Saturday 12:30

使用此功能或如何正确使用它?

 var d=new Date();
var t=d.getTime();

最佳答案

尝试

var d = new Date();
var dd = d.getDate();
var mm = d.getMonth()+1; //January is 0!
var yy = d.getFullYear();

var weekday=new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";

var day=weekday[d.getDay()];

var h = d.getHours();
var m = d.getMinutes();

alert(yy+"-"+mm+"-"+dd+" "+day+" "+h+":"+m)

DEMO

关于javascript - JS - 如何获取并计算当前日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21203449/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com