Solved

timestamp conversion

Posted on 2004-09-10
6
736 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mask rule in struts validation.xml 5 99
countXY challenge 28 171
by zero exception 10 69
dao vs facade design patterns 2 33
Facebook has became the #1 social media platform. People share many funny videos there, yet you don't know how to download them? Now you can download Videos from Facebook in just 3 simple steps.
Building a cohesive image for your brand is vital to making an impression on consumers. When the economy is tough, brands do better than unbranded  products. This can have a huge impact on your long-term profits, as the economy goes up and down.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

756 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