Jump to content

Working with Date


chrisciscoioio

Recommended Posts

Hello,So this code have should set the date of one week from today to the current year month and current day + 7 (or a variable in the end)Now from what I have read this should work, but I keep getting errors back, but they are blank just giving me useless number, not even a line number :)In the final result this will be used to generate a cookie that expires the following monday at 12:00:00:00 AM.I will be passing a variable instead of the 7 for the next week, it shoudl automaticly increase the years, months?

var date = new Date();	var nextWeek = Date.UTC(date.getFullYear(),date.getMonth(),(date.getDate() + 7),0,0,0,0);	alert(nextWeek.toGMTString());

Link to comment
Share on other sites

Date.UTC returns a time value as a number instead of creating a Date object. As nextWeek is therefore not a Date object, the toGMTString call will be failing.How about using setDate to add the 7 days:

var d = new Date();d.setDate( d.getDate()+7 );	alert(d.toGMTString());alert(d.toUTCString());

PS I just saw that toGMTString() is now deprecated and we should use toUTCString() instead.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...