Count Down Date/Time Issue

Hi All,

I am thinking to write a code by using JSP to count down Date and Time. I have one field in my microsoft access format as Date/Time. I want to get the remain time by using the time in my microsoft access minus the current time in the machine and then count down the remain time.

Could you please advise?

Kimsan

[343 byte] By [Scrollbara] at [2007-10-2 20:10:08]
# 1
you can use javascript to get the current time of your client machine.. if you will use java/scriptlet or something you will get the server time.. you can fetch data in a string format and you can parse it to date.
jgalacambraa at 2007-7-13 22:50:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Hi,Thank for your reply.Could you please give me a basic clue on that?Kimsan
Scrollbara at 2007-7-13 22:50:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
may ill give you a detail tommorrow
jgalacambraa at 2007-7-13 22:50:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Ok, thank you very in advance.Kimsan
Scrollbara at 2007-7-13 22:50:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

here's the javascripts i have:

var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");

function countup(ngayon){

var yr = ngayon.substring(6,10);

var d = ngayon.substring(3,5);

var m = ngayon.substring(0,2);

countup1(yr,m,d);

}

function countup1(yr,m,d) {

var today=new Date();

var todayy=today.getYear();

var now = today.getDay();

if ((navigator.appName == "Microsoft Internet Explorer") && (todayy < 2000))

todayy="19" + todayy;

if (navigator.appName == "Netscape")

todayy=1900 + todayy;

var todaym=today.getMonth();

var todayd=today.getDate();

var todaystring=montharray[todaym]+" "+todayd+", "+todayy;

var paststring=montharray[m-1]+" "+d+", "+yr;

var difference=(Math.round((Date.parse(todaystring)-Date.parse(paststring))/(24*60*60*1000))*1);

var diff = 0;

diff = 7-now;

alert(diff)

}

you will call the function countup for sampple app and pass to it the value of textbox which is in date format mm/dd/yyyy.. you can now manipulate dates using those functions.. the function outputs the difference of the date today and the date you entered on a a textbox

jgalacambraa at 2007-7-13 22:50:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

hi,

Thank you very much for the JavaScript. I actually need the count down date and time in JSP for part of my assignment. The assignment is about the online auction that the user can put the deadline of the biding on their products while they register their product to sell.

Is there any way by using JSP?

Thank you very much for your time.

Kimsan

Scrollbara at 2007-7-13 22:50:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
yes partucularly that code that is give is only one user input.. the input date will be in the mm/dd/yyyy format.. but must be less than the on the clients workstation..
jgalacambraa at 2007-7-13 22:50:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

Hi,

The count down of date and time will be a huge issue for me, cus i even dont know JavaScript and i also dont know how to use with the code provided. However, i really appreciate on that and i have learned a lot.

I have other problems and it's also part of my auction application. I use my below code to call the data from my microsoft access and the users can do the biding with those products by clicking on the BID button and then just need to input their biding price.

The problems are:

I have to create a history list of the biding and store those data in my table and other users can see the history of the biding. However, i dont know how catch the data that i already on my page and place in my history table. Because the way that i see those data on my page just the normal text.

The code that i use to generate the data from my table and display on my page is below:

<HTML>

<HEAD>

<TITLE>Welcome to the online Auction.......</TITLE>

</HEAD>

<BODY>

<%@ page language ="java" import = "java.io.*" import = "java.lang.*" import = "java.sql.*" %>

<font font face = "Viner Hand ITC" size= 10>

<center>Welcome to the online Auction....</center>

</font>

<% try

{

String strUsername = request.getParameter("username");

out.print("<center><h1>");

out.print("Welcome ?);

out.print(strUsername);

out.print("</h1></center>");

out.print("<center>");

out.print("<BR><BR>");

out.print("<font font face = Viner Hand ITC size= 5>Products on sales</font>");

out.print("<BR><BR>");

Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");

Connection myConn = DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=C:/Auction/Auction.mdb");

Statement myStatement = myConn.createStatement ();

ResultSet myResult = myStatement.executeQuery("SELECT * FROM tblProduct");

ResultSetMetaData myResultSet = myResult.getMetaData();

out.println("<font face=Tahoma>");

out.print("<table border=1>");

out.print("<TR>");

out.print("<TD width = 180> Item Title");out.print("</TD>");

out.print("<TD width = 180> Description");out.print("</TD>");

out.print("<TD width = 180> Current bid");out.print("</TD>");

out.print("</TR>");

out.print("</table>");

while(myResult.next())

{

out.print("<table border=1>");

out.print("<TR>");

out.print("<TD width = 200>");

out.println(myResult.getString(1));

out.print("</TD>");

out.print("<TD width = 200>");

out.println(myResult.getString(4));

out.print("</TD>");

out.print("<TD width = 200>");

out.println(myResult.getString(3));

out.print("</TD>");

//out.println(myResult.getString(4));

out.print("<TD>");

out.print("<form action=buy_page.jsp method=post>");

out.print("<input type=submit name=okfunc value=Bid>");

out.print("</TD>");

out.print("</form>");

out.print("</TR>");

out.print("</table>");

}

out.println("</font>");

out.print("</center>");

myConn.close();

}

catch(Exception e){}

%>

</BODY>

</HTML>

I also need to embed the JavaScript that you provided in that code next to my biding buttion.

Do you have any suggestion?

Could you please advise?

Kimsan

Scrollbara at 2007-7-13 22:50:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9
then? what you want to do? do you want to make links on every bidding?
jgalacambraa at 2007-7-13 22:50:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10

Hi,

I just updated my code by adding a text box for placing bid. After the user put in the biding price and click on the biding button then i want the all the data in the same row of button that user just clicked store in my History table. And i also want to record the time of user placing bid in that table.

I dont know how to get the data from my page because all those data just get from my other table in microsoft access and only the text box that i think possible for me to get into my table.

The code are below:

<html>

<head>

<title>Welcome to the online Auction...</title></head>

<body>

<%@ page language ="java" import = "java.io.*, java.lang.*, java.sql.*" %>

<% try

{

String strUsername = request.getParameter("username");

String strPassword = request.getParameter("password");

Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");

Connection myConn = DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=C:/Auction/Auction.mdb");

String strSQL = "SELECT [UserName], [Password] FROM tblUserDetails where [UserName] = ? and [Password] = ?";

PreparedStatement statement = myConn.prepareStatement(strSQL);

statement.setString(1, strUsername);

statement.setString(2, strPassword);

ResultSet myResult = statement.executeQuery();

{

if(myResult.next())

{

//out.println("Login Succesful! A record with the given user name and password exists");

out.print("<center><h1>");

out.print("Welcome &nbsp;");

out.print(strUsername);

out.print("</h1></center>");

out.print("<center>");

out.print("<BR><BR>");

out.print("<font font face = Viner Hand ITC size= 5>Products on sales</font>");

out.print("<BR><BR>");

Statement myStatement = myConn.createStatement ();

ResultSet myResult1 = myStatement.executeQuery("SELECT * FROM tblProduct");

ResultSetMetaData myResultSet = myResult1.getMetaData();

out.println("<font face=Tahoma>");

out.print("<table border=1 CELLSPACING=0>");

out.print("<TR>");

out.print("<TD width = 200> Item Title");out.print("</TD>");

out.print("<TD width = 200> Description");out.print("</TD>");

out.print("<TD width = 200> Current bid");out.print("</TD>");

out.print("<TD width = 200> Available Time");out.print("</TD>");

out.print("<TD width = 200> Place Bid");out.print("</TD>");

out.print("</TR>");

out.print("</table>");

while(myResult1.next())

{

out.print("<table border=1 CELLSPACING=0>");

out.print("<TR>");

out.print("<TD width = 200>");

out.println(myResult1.getString(1));

out.print("</TD>");

out.print("<TD width = 200>");

out.println(myResult1.getString(3));

out.print("</TD>");

out.print("<TD width = 200>");

out.println(myResult1.getString(2));

out.print("</TD>");

out.print("<TD width = 200>");

out.println(myResult1.getString(4));

out.print("</TD>");

out.print("<TD>");

out.print("<form action=biding_form.html method=post>");

out.print("<input type=text name=place_bid>");

out.print("<input type=submit name=okfunc value=Bid>");

out.print("</TD>");

out.print("</form>");

out.print("</TR>");

out.print("</table>");

}

out.println("</font>");

out.print("</center>");

}

else

{

out.print("<center>");

out.print("Sorry&nbsp;");

out.print("<font color = RED size = 5>");

out.print(strUsername);

out.print("</font>");

out.print("&nbsp;could not be found.");

out.print("</center>");

}

}

myResult.close();

statement.close();

myConn.close();

}

catch(SQLException e)

{

out.println(e);

}

%>

</body>

</html>

Could you please advise? How can i process it?

Kimsan

Scrollbara at 2007-7-13 22:50:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 11
you have a textbox but you didn't store it on your db.. one way to store it is to make a code block for inserting something to your db on your jsp.. i cannot see how can you store it
jgalacambraa at 2007-7-13 22:50:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 12
Hi,So do have any suggestion for me? I really dont know to get this part work.Thanks and best regards,Kimsan
Scrollbara at 2007-7-13 22:50:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 13
yes put a code block for inserting the value of your textbox on the db at the top part of your jsp
jgalacambraa at 2007-7-13 22:50:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 14

Hi,

I think the explaination of my problem was not clear enough.

For example, I have two JSP page as below:

test1.jsp

I try to get the vaule from my textbox by using:

String strUser = request.getParameter ("strUserName");

Then i print out by using: out.print(strUser); then i can get the value and put on my page (For example, i get ABC on my page).

-

test2.jsp

Next, i want to get the value from strUser (which mean that the one i already display on page in test1.jsp, ABC) to insert into my table by using INSERT INTO statement. Then i try by using

String strUser1 = request.getParameter ("strUser");

Is it possbile for me to do that? I cannot get anything to insert into my table. Then i tried out.print(strUser1); then i found that i get NULL value.

So is it possible for me to do that? Or could you please adives how can i process it?

B.Regards,

Kimsan

Scrollbara at 2007-7-13 22:50:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...