Jump to content

Working with Date


chrisciscoioio
 Share

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...