Solved

timestamp conversion

Posted on 2004-09-10
6
731 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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Export JSON response data to Excel in IE9 3 76
password protect pdf 11 76
error when compiling my project in eclipse luna 30 415
maven webservice example issue 2 138
The question appears often enough, how do I transfer my data from my old server to the new server while preserving file shares, share permissions, and NTFS permisions.  Here are my tips for handling such a transfer.
This problem is more common than not and I will show you some things to check to solve this problem.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

803 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