Solved

timestamp conversion

Posted on 2004-09-10
6
728 Views
Last Modified: 2012-05-05
Hello,

I have a timestamp in my database in the format of: 0000-00-00 00:00:00

I am currently using

        Date date = nc.getItemNameDate();
        String s = DateFormat.getDateInstance(DateFormat.FULL).format(date);

to convert it to: Saturday, July 4, 2004

what method would I use so it shows the date like it is above, but also has the time on the end?

thanks!
0
Comment
Question by:k41d3n
  • 2
6 Comments
 
LVL 7

Expert Comment

by:lhankins
ID: 12030873
You can use the SimpleDateFormat class to accomplish this. For example, the following snippet :

      SimpleDateFormat sdf = new SimpleDateFormat("EEEEEEE, MMMMM, yyyy HH:mm:ss");
      System.out.println("date = [" + sdf.format(new Date()) + "]");

Will produce something that looks like this :

      date = [Friday, September, 2004 15:50:17]

You can read more about SimpleDateFormat format strings in the JavaDoc here :

      http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html

0
 
LVL 11

Accepted Solution

by:
sompol_kiatkamolchai earned 168 total points
ID: 12037874
EEEEEEE, MMMMM d, yyyy HH:mm:ss

or

EEEEEEE, MMMMM dd, yyyy HH:mm:ss

You forgot date :)
0
 
LVL 7

Assisted Solution

by:lhankins
lhankins earned 166 total points
ID: 12038822
Yup, sorry, it does need the dd too.   So it should be :

     SimpleDateFormat sdf = new SimpleDateFormat("EEEEEEE, MMMMM dd, yyyy HH:mm:ss");
     System.out.println("date = [" + sdf.format(new Date()) + "]");

then it will print in the format :

     date = [Friday, September 10, 2004 15:50:17]
0
 
LVL 19

Assisted Solution

by:Kuldeepchaturvedi
Kuldeepchaturvedi earned 166 total points
ID: 12041093
if your data type in the database is of Date then you do not have to do any conversion.
just make a prepared statement and insert the date as is.
PS = "insert into table1 set timestamp=?";
PS.setDate(new Date());
will work as well.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Lotus Notes – formerly IBM Notes – is an email client application, while IBM Domino (earlier Lotus Domino) is an email server. The client possesses a set of features that are even more advanced as compared to that of Outlook. Likewise, IBM Domino is…
A customer recently asked me about anti-malware and the different deployment options available for his business. Daily news about cyberattacks, zero-day vulnerabilities, and companies that suffered a security breach made him wonder if the endpoint a…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now