participate


New To Java - How can I obtain System date and time?
<<   Back to Forum  |   Give us Feedback
This topic has 7 replies on 1 page.
BCE_Jose
Posts:87
Registered: 11/4/06
How can I obtain System date and time?   
Mar 30, 2007 6:49 AM

 
Good morning to everyone !,

Could anybody help me?

I need to know how to get the current System time... ??

I need the source code to get it as a Timestamp. I think this type belongs to the class java.sql.Timestamp

Which is the easiest way to do this?

I need to get it, to insert it in a database datetime field afterwards.

Thanks in advance for your time.
 
zadok
Posts:4,003
Registered: 8/7/06
Re: How can I obtain System date and time?   
Mar 30, 2007 6:54 AM (reply 1 of 7)  (In reply to original post )

 
Why not just use getDate() in SQL?

Anyway in Java just use
System.currentTimeMillis()
and convert it to a TimeStamp
 
Setter
Posts:15
Registered: 3/27/07
Re: How can I obtain System date and time?   
Mar 30, 2007 6:55 AM (reply 2 of 7)  (In reply to original post )

 
Try:
Timestamp time = new Timestamp(System.currentTimeMillis());


Also:
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html#currentTimeMillis()
and
http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Timestamp.html
 
deepak_cucek
Posts:85
Registered: 3/26/07
Re: How can I obtain System date and time?   
Mar 30, 2007 6:55 AM (reply 3 of 7)  (In reply to original post )

 
hi
Date d1=new Date();
d1 will contains current system date and time..
is that enough
 
BCE_Jose
Posts:87
Registered: 11/4/06
Re: How can I obtain System date and time?   
Mar 30, 2007 7:00 AM (reply 4 of 7)  (In reply to #3 )

 
Hello again, thanks for all the kind replies...

I think I will go for this Option:

Timestamp time = new Timestamp(System.currentTimeMillis());


Seems very coherent to me. Do you know If I can insert it inside a datetime field of a DB Table?

Thank you guys, you always exceed my expectations

Sincerely, Jose
 
G_Abubakr
Posts:654
Registered: 5/20/06
Re: How can I obtain System date and time?   
Mar 30, 2007 7:39 AM (reply 5 of 7)  (In reply to #4 )

 
which database are you using
 
BCE_Jose
Posts:87
Registered: 11/4/06
Re: How can I obtain System date and time?   
Mar 30, 2007 12:06 PM (reply 6 of 7)  (In reply to #5 )

 
I am using

SYBASE

thanks...
 
DrClap
Posts:38,727
Registered: 4/30/99
Re: How can I obtain System date and time?   
Mar 30, 2007 1:08 PM (reply 7 of 7)  (In reply to #4 )

 
Seems very coherent to me. Do you know If I can
insert it inside a datetime field of a DB Table?

Yes, it's easy to do that with a PreparedStatement.
 
This topic has 7 replies on 1 page.
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics
    Users Online : 63
  • Guests : 118

About Sun forums
  • Sun Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Sun Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums