0

On my website I have a clock, the code you can find below, what I need to do is offset the date for 2 weeks into the future. The reason for this is that this clock will display the eta time and date for products. They take 2 weeks to get to the client.

Is this possible? If so could you please show me how to adjust the date?

Thanks in advance.

JAVASCRIPT

<script type="text/javascript">
tday=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
tmonth=new Array("January","February","March","April","May","June","July","August","September","October","November","December");

function GetClock(){
var d=new Date();
var nday=d.getDay(),nmonth=d.getMonth(),ndate=d.getDate(),nyear=d.getYear(),nhour=d.getHours(),nmin=d.getMinutes(),nsec=d.getSeconds(),ap;

 if(nhour==0){ap=" AM";nhour=12;}
 else if(nhour<12){ap=" AM";}
 else if(nhour==12){ap=" PM";}
 else if(nhour>12){ap=" PM";nhour-=12;}

 if(nyear<1000) nyear+=1900;
 if(nmin<=9) nmin="0"+nmin;
 if(nsec<=9) nsec="0"+nsec;

 document.getElementById('clockbox').innerHTML=""+tday[nday]+", "+tmonth[nmonth]+" "+ndate+", "+nyear+" "+nhour+":"+nmin+":"+nsec+ap+"";
 }

 window.onload=function(){
 GetClock();
 setInterval(GetClock,1000);
 }
 </script>

HTML

 <div id="clockbox"></div>
gregg legg
  • 13
  • 4
  • 2
    I think this has already been answered. Take a look at http://stackoverflow.com/questions/7751936/javascript-date-plus-2-weeks-14-days All you need to do is set var d=new Date(+new Date + 12096e5); – okisinch Feb 20 '15 at 15:08
  • Please remove `if(nyear<1000) nyear+=1900;` and change `.getYear()` to `.getFullYear()` see http://jsfiddle.net/mplungjan/h46aLmgv/ – mplungjan Feb 20 '15 at 15:18

1 Answers1

-1

Date in JS can get tricky. You're better off using a date library like Date.js. The .add() method will be helpful to you or you can always call .parse("+2 weeks")

Lou Fancy
  • 156
  • 7