thunderchicken
asked on
Date problem, part 2
I am passing in 3 dates from an HTML page:
<PARAM NAME = "date" Value="04/04/2002 01:00:00AM,04/04/2002 23:00:00PM,04/05/2002 01:00:00AM">
The difference is 22 hours and 2 hours, however when i try to convert it based on the code below, I get
0 0.0
1 13.0
2 720.0
It seems like if they are on the same day it works fine, but when you go to the next day, it should calculate 24.0, not 720? I try 04/05/2002 03:00:00AM and it just adds 2 on it.
import java.awt.*;
import java.applet.Applet;
import java.util.*;
import java.lang.*;
import java.text.*;
public class graph extends Applet
{
public void paint(Graphics g)
{
int Y1 = 10;
int Y2 = 350;
int X1 = 50;
int X2 = 550;
int ySpan = 8;
String dates = getParameter("date");
String data = getParameter("data");
java.text.SimpleDateFormat date_format = new java.text.SimpleDateFormat ("dd/MM/yy yy hh:mm:ssa");
StringTokenizer aryData = new StringTokenizer(data,",");
StringTokenizer aryDates = new StringTokenizer(dates,",") ;
int numitems = aryData.countTokens();
String[] arydates = new String[numitems];
long[] aryDTdiff = new long[numitems];
DateFormat df = DateFormat.getDateInstance ();
for (int i=0;i<numitems;i++)
{
arydates[i] = aryDates.nextToken();
try{aryDTdiff[i] = date_format.parse(arydates [i]).getTi me();}
catch(java.text.ParseExcep tion e){};
}
//initalize them
float lowVal = Float.valueOf(aryData.next Token()).f loatValue( );
float highVal = lowVal;
for (int i=1;i<numitems;i++)
{
float tempVal = Float.valueOf((aryData.nex tToken())) .floatValu e();
if (tempVal > highVal) highVal = tempVal;
if (tempVal < lowVal) lowVal = tempVal;
}
//cycle through the Y Coordinate values
g.drawString(Float.toStrin g(highVal+ 1.0f),X1-3 5,Y1+5);
g.drawLine(X1-2,Y1,X1+5,Y1 );
NumberFormat nf = NumberFormat.getNumberInst ance();
for (int i=1; i<=ySpan;i++)
{
double d = (highVal - (highVal-lowVal)/ySpan) - (highVal-lowVal)/ySpan * i;
nf.setMaximumFractionDigit s(2);
d = new Double(nf.format(d)).doubl eValue();
float f = (float)d;
g.drawLine(X1-2,(Y2-Y1)/yS pan*i,X1+5 ,(Y2-Y1)/y Span*i);
g.drawString(Float.toStrin g(f),X1-35 ,(Y2-Y1)/y Span*i + 5);
}
for (int q=(numitems-1); q >= 0; q--)
{
g.drawString(Integer.toStr ing(q) + " " + Float.toString((aryDTdiff[ q]-aryDTdi ff[0])/100 0/60/60),X 1+200,Y1*( q+20));
//g.drawString(Integer.toS tring(q) + " " + date_format.parse(arydates [q]).getTi me(),X1+20 0,Y1*(q+20 ));
//g.drawString(Integer.toS tring(q) + " 44",X1+200,Y1*(q+20));
}
//draw graph layout thingy
g.setColor(Color.black);
g.drawLine(X1,Y1,X1,Y2);
g.drawLine(X1,Y2,X2,Y2);
} // end paint
}// end graph Applet
<PARAM NAME = "date" Value="04/04/2002 01:00:00AM,04/04/2002 23:00:00PM,04/05/2002 01:00:00AM">
The difference is 22 hours and 2 hours, however when i try to convert it based on the code below, I get
0 0.0
1 13.0
2 720.0
It seems like if they are on the same day it works fine, but when you go to the next day, it should calculate 24.0, not 720? I try 04/05/2002 03:00:00AM and it just adds 2 on it.
import java.awt.*;
import java.applet.Applet;
import java.util.*;
import java.lang.*;
import java.text.*;
public class graph extends Applet
{
public void paint(Graphics g)
{
int Y1 = 10;
int Y2 = 350;
int X1 = 50;
int X2 = 550;
int ySpan = 8;
String dates = getParameter("date");
String data = getParameter("data");
java.text.SimpleDateFormat
StringTokenizer aryData = new StringTokenizer(data,",");
StringTokenizer aryDates = new StringTokenizer(dates,",")
int numitems = aryData.countTokens();
String[] arydates = new String[numitems];
long[] aryDTdiff = new long[numitems];
DateFormat df = DateFormat.getDateInstance
for (int i=0;i<numitems;i++)
{
arydates[i] = aryDates.nextToken();
try{aryDTdiff[i] = date_format.parse(arydates
catch(java.text.ParseExcep
}
//initalize them
float lowVal = Float.valueOf(aryData.next
float highVal = lowVal;
for (int i=1;i<numitems;i++)
{
float tempVal = Float.valueOf((aryData.nex
if (tempVal > highVal) highVal = tempVal;
if (tempVal < lowVal) lowVal = tempVal;
}
//cycle through the Y Coordinate values
g.drawString(Float.toStrin
g.drawLine(X1-2,Y1,X1+5,Y1
NumberFormat nf = NumberFormat.getNumberInst
for (int i=1; i<=ySpan;i++)
{
double d = (highVal - (highVal-lowVal)/ySpan) - (highVal-lowVal)/ySpan * i;
nf.setMaximumFractionDigit
d = new Double(nf.format(d)).doubl
float f = (float)d;
g.drawLine(X1-2,(Y2-Y1)/yS
g.drawString(Float.toStrin
}
for (int q=(numitems-1); q >= 0; q--)
{
g.drawString(Integer.toStr
//g.drawString(Integer.toS
//g.drawString(Integer.toS
}
//draw graph layout thingy
g.setColor(Color.black);
g.drawLine(X1,Y1,X1,Y2);
g.drawLine(X1,Y2,X2,Y2);
} // end paint
}// end graph Applet
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Jesus, I'm stupid.
Thanks
Thanks
ASKER
<PARAM NAME = "date" Value="04/04/2002 01:00:00AM,04/04/2002 2:00:00PM,04/05/2002 01:00:00AM">