JS如何获取北京时间

JS如何获取北京时间,第1张

参考代码如下:

<SCRIPT LANGUAGE = "JavaScript">

var xml;

var d = new Date(),

    dd = dgetDay(),

    friday = new Date((5 - dd)(3600241000)+dgetTime())getDate();

alert(friday);

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 40 Transitional//EN">

<HTML>

<HEAD>

<TITLE> New Document </TITLE>

<META NAME="Generator" CONTENT="EditPlus">

<META NAME="Author" CONTENT="">

<META NAME="Keywords" CONTENT="">

<META NAME="Description" CONTENT="">

</HEAD>

<BODY>

<SCRIPT language=JavaScript>

function Year_Month(){

var now = new Date();

var yy = nowgetYear();

var mm = nowgetMonth()+1;

var cl = '<font color="#333333">';

if (nowgetDay() == 0) cl = '<font color="#333333">';

if (nowgetDay() == 6) cl = '<font color="#333333">';

return(cl + yy + '年' + mm + '月</font>'); }

function Date_of_Today(){

var now = new Date();

var cl = '<font color="#ff0000">';

if (nowgetDay() == 0) cl = '<font color="#333333">';

if (nowgetDay() == 6) cl = '<font color="#333333">';

return(cl + nowgetDate() + '</font>'); }

function Day_of_Today(){

var day = new Array();

day[0] = "星期日";

day[1] = "星期一";

day[2] = "星期二";

day[3] = "星期三";

day[4] = "星期四";

day[5] = "星期五";

day[6] = "星期六";

var now = new Date();

var cl = '<font color="#333333">';

if (nowgetDay() == 0) cl = '<font color="#333333">';

if (nowgetDay() == 6) cl = '<font color="#333333">';

return(cl + day[nowgetDay()] + '</font>'); }

function CurentTime(){

var now = new Date();

var hh = nowgetHours();

var mm = nowgetMinutes();

var ss = nowgetTime() % 60000;

ss = (ss - (ss % 1000)) / 1000;

var clock = hh+':';

if (mm < 10) clock += '0';

clock += mm+':';

if (ss < 10) clock += '0';

clock += ss;

return(clock); }

function refreshCalendarClock(){

documentallcalendarClock1innerHTML = Year_Month();

documentallcalendarClock2innerHTML = Date_of_Today();

documentallcalendarClock3innerHTML = Day_of_Today();

documentallcalendarClock4innerHTML = CurentTime(); }

var webUrl = webUrl;

documentwrite('<table border="0" cellpadding="0" cellspacing="0"><tr><td>');

documentwrite('<table id="CalendarClockFreeCode" border="0" cellpadding="0" cellspacing="0" width="60" height="70" ');

documentwrite('style="position:absolute;visibility:hidden" bgcolor="#eeeeee">');

documentwrite('<tr><td align="center"><font ');

documentwrite('style="cursor:hand;color:#ff0000;font-family:宋体;font-size:14pt;line-height:120%" ');

if (webUrl != 'netflower'){

documentwrite('</td></tr><tr><td align="center"><font ');

documentwrite('style="cursor:hand;color:#2000ff;font-family:宋体;font-size:9pt;line-height:110%" ');

}

documentwrite('</td></tr></table>');

documentwrite('<table border="0" cellpadding="0" cellspacing="0" width="61" height="70">');

documentwrite('<tr><td valign="top" width="100%" height="100%">');

documentwrite('<table border="0" cellpadding="0" cellspacing="0" width="58" height="67">');

documentwrite('<tr><td align="center" width="100%" height="100%" >');

documentwrite('<font id="calendarClock1" style="font-family:宋体;font-size:9pt;line-height:120%"> </font><br>');

documentwrite('<font id="calendarClock2" style="color:#333333;font-family:Arial;font-size:14pt;line-height:120%"> </font><br>');

documentwrite('<font id="calendarClock3" style="color:#333333;font-family:宋体;font-size:9pt;line-height:120%"> </font><br>');

documentwrite('<font id="calendarClock4" style="color:#333333;font-family:宋体;font-size:9pt;line-height:120%"><b> </b></font>');

documentwrite('</td></tr></table>');

documentwrite('</td></tr></table>');

documentwrite('</td></tr></table>');

setInterval('refreshCalendarClock()',1000);

</SCRIPT>

</BODY>

</HTML>

前言:需求里面有,做了就记录一下

第一种:获取当前月 当前周 的第一天 时分秒都为0,最后一天时分秒为23:59:59

ps:如果想获得指定日期的当前周,new Date('2020-1-2') 传参就可以了

//获取当前周

getTime(){

var date = new Date();

// 本周一的日期

datesetDate(dategetDate() - dategetDay() + 1);

var begin = dategetFullYear() + "-" + (dategetMonth() + 1) + "-" + dategetDate() + " 00:00:00";

// 本周日的日期

datesetDate(dategetDate() + 6);

var end = dategetFullYear() + "-" + (dategetMonth() + 1) + "-" + dategetDate() + " 23:59:59";

let timeInfo={

begin:begin,

end:end

}

return timeInfo

}

//获取当前月

getMtime(){

var data=new Date();

datasetDate(1);

datasetHours(0);

datasetSeconds(0);

datasetMinutes(0);

var start = datagetTime();

var currentMonth = datagetMonth();

var nextMonth = ++currentMonth;

var nextMonthFirstDay = new Date(

datagetFullYear(),

nextMonth,

1

);

var end = nextMonthFirstDay-1;

let timeInfo={

begin: thistimestampToTime(start),//这里调用时间戳转年月日时分秒方法

end: thistimestampToTime(end)

}

return timeInfo

}

//时间戳转年月日时分秒方法

timestampToTime (cjsj) {

var date = new Date(cjsj) //时间戳为10位需1000,时间戳为13位的话不需乘1000

var Y = dategetFullYear() + '-'

var M = (dategetMonth()+1 < 10 '0'+(dategetMonth()+1) : dategetMonth()+1) + '-'

var D = (dategetDate() < 10 '0'+dategetDate() : dategetDate()) + ' ';

var h = (dategetHours() < 10 '0'+dategetHours() : dategetHours()) + ':';

var m = (dategetMinutes() < 10 '0'+dategetMinutes() : dategetMinutes())+ ':';

var s = (dategetSeconds() < 10 '0'+dategetSeconds() : dategetSeconds());

return Y+M+D+h+m+s;

}

以上就是关于JS如何获取北京时间全部的内容,包括:JS如何获取北京时间、js中如何获取本周五的日期、JS代码获取日期时间的网页等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/9385492.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-27
下一篇 2023-04-27

发表评论

登录后才能评论

评论列表(0条)

保存