Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date setTime Error

Status
Not open for further replies.

m4uConcept

Programmer
Jul 22, 2002
4
0
0
AT
Mybe anyone had this problem before or knows whats wrong whith the following code:

<script language='JavaScript'>
var calcDate = new Date(2003,9,15);
var ms = calcDate.getTime();
ms = ms + (12*24*60*60*1000);
calcDate.setTime(ms);

day = parseInt(calcDate.getDate(), 10);
month = parseInt(calcDate.getMonth(), 10)+1;
year = parseInt(calcDate.getYear() ,10);
hours = parseInt(calcDate.getHours() ,10);
minutes = parseInt(calcDate.getMinutes() ,10);

clickDateStr = day+&quot;-&quot;+month+&quot;-&quot;+
year+&quot; &quot;+hours+&quot;:&quot;+minutes;
alert(clickDateStr);
</script>

the script adds 12 days to the 15-10-2003!

result on my pc: 26-10-2003 23:0
in my opinion the result must be 27-10-2003 0:0

with var calcDate = new Date(2003,8,15); everything works fine... hoping for help

Thx Roland



 
m4uConcept, Here ya go:
Code:
<script language='JavaScript'>
  var calcDate = new Date();
  var ms = calcDate.getTime();
  ms = ms + (12*60*60*1000);
  calcDate.setTime(ms);
        
  day = parseInt(calcDate.getDate());
  month = parseInt(calcDate.getMonth(), 10)+1;
  year = parseInt(calcDate.getFullYear());
  hours = parseInt(calcDate.getHours() ,10);
  minutes = parseInt(calcDate.getMinutes() ,10);
        
  clickDateStr = day+&quot;-&quot;+month+&quot;-&quot;+year+&quot;  &quot;+hours+&quot;:&quot;+minutes;
  alert(clickDateStr);
</script>

I have this little thing, Advanced Delusionary Schizophrenia with Involuntary Narcissistic Rage.
It's no big deal really...
 
You have forgotten to add the ms (millisecond) value with 24 (a day has 24 hours)
 
I've solved the problem

The clue is the change from daylight saving time to wintertime. Thats the reason where the one hour has stayed!

greetings Roland
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top