Solved

timestamp conversion

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
First of all let me say that the only language that I speak is English, but in answering questions here I often come across people whose English skills are not the best and I’d like to be able to communicate better with them, and the following descr…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

617 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