Solved

timestamp conversion

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
communication with a non technical owner 16 98
tomcat users xml 7 101
lessBy10  challenge 15 89
Market Place not working in Eclipse Luna 2 84
In this article, I will show you HOW TO: Install VMware Tools for Windows on a VMware Windows virtual machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, using the VMware Host Client. The virtual machine has Windows Server 2016 instal…
A Short Story about the Best File Recovery Software – Acronis True Image 2017
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 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

13 Experts available now in Live!

Get 1:1 Help Now