This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes How do I get date and time seperate from Date Object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How do I get date and time seperate from Date Object" Watch "How do I get date and time seperate from Date Object" New topic
Author

How do I get date and time seperate from Date Object

Ajoo Bar
Ranch Hand

Joined: Mar 28, 2011
Posts: 30
Date date = trade.getValueDate();
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
dateFormat.format(date);
//get current date time with Calendar()
Calendar cal = Calendar.getInstance();
//logger.debug("Date is " cal.getTime());
logger.debug("Trade Time is " + dateFormat.format(cal.getTime().getTime())); here i want time to be in HH:mm:ss formate 12:53:52
logger.debug("trade Date is" + dateFormat.format(cal.getTime())); Here I want data to be in yyyy/MM/dd format 2011/11/16

Thanks
Ajoo
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4341
    
    7

If you want outputs in a different format, use different SimpleDateFormat objects with the patterns that you want.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How do I get date and time seperate from Date Object
 
Similar Threads
Convert the String to date format
using Dates and times
GMT time displaying
System Date
how to change the date,Time format after accessing it from the database