Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to take date in Java??

Status
Not open for further replies.

Bartec

Programmer
Jan 21, 2005
54
PL
Hi!

I have quite stupid problem... I don't know how to take a date from Java. I know I should use Date class for example:
Code:
......
      Date dd = new Date();
      dd.getDate(); //<--------- this is not available.
      dd.getTime(); //<----------this is available but the
                    // I receive quite stupid format

//Works only this (example):
  JOptionPane.showMessageDialog(null, new Date().toString(),
                                     "Test",JOptionPane.INFORMATION_MESSAGE);

So if anybody have some solution please response my thread.
Thanks for any help

Best regards

Bartec

 
What do you mean bu "stupid format"?

Maybe you should take a look at Calendar class and System.currentTimeMillis method.

Cheers,
Dian
 
stupid format" ?

Perhaps you explain what would be a "sensible format" for you !
It helps when posting questions to explain clearly what you have, and what you wish - giving examples if possible.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Explain "stupid format":)

123232455664 //<-------quite strange??

 
hmmmmm

Maybe I convert long to string in bad way??

Code:
long l =  System.currentTimeMillis();
          
          String str =  Long.toString(l);

Maybe it's not correct??

 
Date.getTime() returns the number of milliseconds since January 1st 1970 - this is standard in computing.

As I said before : What format do you actually want ???

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Actually I need time format: hh:mm:ss
date format: dd:MM:YYYY

 
Finally, it only took 6 posts to get what your real problem is !

Use the java.text.SimpleDateFormat class, here is an example :


SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String formattedDate = sdf.format(new java.util.Date());

See the API docs for more information.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top