Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

server date

 
shyamkumar bopannachengalaiah
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 689
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

hi,

I think you can get date and time using

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

 
Kalyan Ram
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic