JS中已经知道一个日期如何获取7天后的那个日期

JS中已经知道一个日期如何获取7天后的那个日期,第1张

JS实现简单获取7天后日期方法:

function fun_date(aa)

{

var date1 = new Date(),

time1=date1getFullYear()+"-"+(date1getMonth()+1)+"-"+date1getDate();//time1表示当前时间

var date2 = new Date(date1);

date2setDate(date1getDate()+aa);       

var time2 = date2getFullYear()+"-"+

(date2getMonth()+1)+"-"+date2getDate();

}

fun_date(7);//7天后的日期

扩展资料

getDate:使用当地时间返回 Date 对象的月份日期值。

getFullYear:使用当地时间返回 Date 对象的年份。

getMonth:使用当地时间返回 Date 对象的月份。

获取 日期 时间 星期

var d = new Date();

var datestr = "今天是: " +dgetFullYear() + "-" +(dgetMonth()+1) + "-" + dgetDate() + " " + dgetHours() + ":" + dgetMinutes() + ":" + dgetSeconds() + " 星期"+"日一二三四五六"charAt(dgetDay())

// 判断闰年

DateprototypeisLeapYear = function()

{

return (0==thisgetYear()%4&&((thisgetYear()%100!=0)||(thisgetYear()%400==0)));

}

// 日期格式化

// 格式 YYYY/yyyy/YY/yy 表示年份

// MM/M 月份

// W/w 星期

// dd/DD/d/D 日期

// hh/HH/h/H 时间

// mm/m 分钟

// ss/SS/s/S 秒

//---------------------------------------------------

DateprototypeFormat = function(formatStr)

{

var str = formatStr;

var Week = ['日','一','二','三','四','五','六'];

str=strreplace(/yyyy|YYYY/,thisgetFullYear());

str=strreplace(/yy|YY/,(thisgetYear() % 100)>9 (thisgetYear() % 100)toString():'0' + (thisgetYear() % 100));

<script type="text/javascript">

var today = new Date();

var day = todaygetDate();//日

var month =todaygetMonth();//月

var year = todaygetYear();//年

if(year<1000)//年分兼容火狐 需要这么判断一下

{

year+=1900;

}

//剩下的赋值问题就很简单了。自己搞吧

</script>

问题不详,请仔细描述你的提问 和你的目的。

var myDate = new Date();

myDatesetFullYear(1992); // 设置年份/

myDategetYear();        //获取当前年份(2位)

myDategetFullYear();    //获取完整的年份(4位,1970-)

myDategetMonth();       //获取当前月份(0-11,0代表1月)

myDategetDate();        //获取当前日(1-31)

myDategetDay();         //获取当前星期X(0-6,0代表星期天)

myDategetTime();        //获取当前时间(从197011开始的毫秒数)

myDategetHours();       //获取当前小时数(0-23)

myDategetMinutes();     //获取当前分钟数(0-59)

myDategetSeconds();     //获取当前秒数(0-59)

myDategetMilliseconds();    //获取当前毫秒数(0-999)

myDatetoLocaleDateString();     //获取当前日期

var mytime=myDatetoLocaleTimeString();     //获取当前时间

myDatetoLocaleString( );        //获取日期与时间

todayDate = new Date();

date = todayDategetDate();

month= todayDategetMonth() +1;

year= todayDategetYear();

documentwrite("今天是")

documentwrite("<br>")

if(navigatorappName == "Netscape")

{

documentwrite(1900+year);

documentwrite("年");

documentwrite(month);

documentwrite("月");

documentwrite(date);

documentwrite("日");

documentwrite("<br>")

}

if(navigatorappVersionindexOf("MSIE") != -1)

{

documentwrite(year);

documentwrite("年");

documentwrite(month);

documentwrite("月");

documentwrite(date);

documentwrite("日");

}

if (todayDategetDay() == 5) documentwrite("星期五")

if (todayDategetDay() == 6) documentwrite("星期六")

if (todayDategetDay() == 0) documentwrite("星期日")

if (todayDategetDay() == 1) documentwrite("星期一")

if (todayDategetDay() == 2) documentwrite("星期二")

if (todayDategetDay() == 3) documentwrite("星期三")

if (todayDategetDay() == 4) documentwrite("星期四")

<script type="text/javascript">

function getYearLastDay(){

return new Date()getFullYear()+"年12月31号";

}

alert(getYearLastDay());

</script>

-------------------------------------------------------------

每年的最后一天的不同的就是年,直接获取年然后加上12月31号,不知道是不是这个意思

Js获取当前日期时间及其它 *** 作

var myDate = new Date();

myDategetYear(); //获取当前年份(2位)

myDategetFullYear(); //获取完整的年份(4位,1970-)

myDategetMonth(); //获取当前月份(0-11,0代表1月)

myDategetDate(); //获取当前日(1-31)

myDategetDay(); //获取当前星期X(0-6,0代表星期天)

myDategetTime(); //获取当前时间(从197011开始的毫秒数)

myDategetHours(); //获取当前小时数(0-23)

myDategetMinutes(); //获取当前分钟数(0-59)

myDategetSeconds(); //获取当前秒数(0-59)

myDategetMilliseconds(); //获取当前毫秒数(0-999)

myDatetoLocaleDateString(); //获取当前日期

var mytime=myDatetoLocaleTimeString(); //获取当前时间

myDatetoLocaleString( ); //获取日期与时间

日期时间脚本库方法列表

DateprototypeisLeapYear 判断闰年

DateprototypeFormat 日期格式化

DateprototypeDateAdd 日期计算

DateprototypeDateDiff 比较日期差

DateprototypetoString 日期转字符串

DateprototypetoArray 日期分割为数组

DateprototypeDatePart 取日期的部分信息

DateprototypeMaxDayOfDate 取日期所在月的最大天数

DateprototypeWeekNumOfYear 判断日期所在年的第几周

StringToDate 字符串转日期型

IsValidDate 验证日期有效性

CheckDateTime 完整日期时间检查

daysBetween 日期天数差

js代码:

//---------------------------------------------------

// 判断闰年

//---------------------------------------------------

DateprototypeisLeapYear = function()

{

return (0==thisgetYear()%4&&((thisgetYear()%100!=0)||(thisgetYear()%400==0)));

}

//---------------------------------------------------

// 日期格式化

// 格式 YYYY/yyyy/YY/yy 表示年份

// MM/M 月份

// W/w 星期

// dd/DD/d/D 日期

// hh/HH/h/H 时间

// mm/m 分钟

// ss/SS/s/S 秒

//---------------------------------------------------

以上就是关于JS中已经知道一个日期如何获取7天后的那个日期全部的内容,包括:JS中已经知道一个日期如何获取7天后的那个日期、js获取当前日期,然后根据当前日期获取到上周周一跟周五的日期,并格式化日期yyyy-MM-dd、根据本地时间获取到当期日期(本月的几号),返回值为1-31之间。在文本框内自动生成.可用js做等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

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

原文地址:https://54852.com/web/9733609.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存