File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes server date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "server date" Watch "server date" New topic
Author

server date

shyamkumar bopannachengalaiah
Ranch Hand

Joined: Dec 30, 2008
Posts: 100
I am developing registration application where i have to store the creation date of the enduser in database. here the creation date should be server date. How can i write the code in my servlet to get the serverdate and insert into the mysql database?
Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 684


hi,

I think you can get date and time using

java.util.Date date = new java.util.Date();


Thanks, Nishan Patel
SCJP 1.5, SCWCD 1.5, OCPJWSD Java Developer,My Blog
Kalyan Ram
Greenhorn

Joined: Dec 29, 2003
Posts: 14
shyamkumar bopannachengalaiah wrote: I am developing registration application where i have to store the creation date of the enduser in database. here the creation date should be server date. How can i write the code in my servlet to get the serverdate and insert into the mysql database?

Is there any specific need for this particular approach? i.e. taking Servlet host's time as the user creation time.

Are the application server and DB server in different timezones? Is there substantial network lag between the application and database servers? Are the user creation SQL statements executed as a batch?

If none of the above cases apply, then simply use the database's now() or similar function as the user creation time i.e. the time when the table row was inserted is taken as the user creation time.

In most cases the user creation date need not be anything beyond something like 08-Apr-2009, 17:09:03. But your requirement might require finer detail?
[edit]
BTW, if you choose to follow the parent's advise, take a look at both java.util.Date/Time and java.sql.Date/Time/Timestamp


regards
/k
shyamkumar bopannachengalaiah
Ranch Hand

Joined: Dec 30, 2008
Posts: 100
Kalyan Ram wrote:
shyamkumar bopannachengalaiah wrote: I am developing registration application where i have to store the creation date of the enduser in database. here the creation date should be server date. How can i write the code in my servlet to get the serverdate and insert into the mysql database?

Is there any specific need for this particular approach? i.e. taking Servlet host's time as the user creation time.

Are the application server and DB server in different timezones? Is there substantial network lag between the application and database servers? Are the user creation SQL statements executed as a batch?

If none of the above cases apply, then simply use the database's now() or similar function as the user creation time i.e. the time when the table row was inserted is taken as the user creation time.

In most cases the user creation date need not be anything beyond something like 08-Apr-2009, 17:09:03. But your requirement might require finer detail?
[edit]
BTW, if you choose to follow the parent's advise, take a look at both java.util.Date/Time and java.sql.Date/Time/Timestamp


regards
/k



thankyou very much.
shyamkumar bopannachengalaiah
Ranch Hand

Joined: Dec 30, 2008
Posts: 100
Nishan Patel wrote:
hi,

I think you can get date and time using

java.util.Date date = new java.util.Date();



thanks for your kind solution.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: server date
 
Similar Threads
How can we get current time
Hibernate Date Issue
Forum and Categorie sorting
Directory creation date
Strange behaviour when using Oracle TO_CHAR to get day of week