Connecting Tech Pros Worldwide Forums | Help | Site Map

Extract time from Calendar Object

Member
 
Join Date: Apr 2008
Location: Philippines
Posts: 35
#1: Oct 17 '09
I just want to extract the time component of the calendar object for comparison to another. Is this possible?

here's my code:
Expand|Select|Wrap|Line Numbers
  1. try {
  2.     String str_date="2009-10-15 12:1:00";
  3.     DateFormat formatter =
  4.         new SimpleDateFormat("yyyy-MM-dd k:mm:ss");
  5.     Date date = (Date)formatter.parse(str_date); 
  6.     Calendar cal = Calendar.getInstance();
  7.     cal.setTime(date);
  8.     System.out.println("Today is " +date );
  9.  
  10.     //need to do something here to get just the time field
  11.     //for comparing. Just the hours, minutes and seconds.
  12.     //I want to do something like
  13.     //if (cal.getTime() > someTimeObject )
  14.     // do something here
  15. } catch (java.text.ParseException e) { e.printStackTrace(); }   
  16.  
thanks!

kind regards.
JR

Member
 
Join Date: Apr 2008
Location: Philippines
Posts: 35
#2: Oct 17 '09

re: Extract time from Calendar Object


bumping this question.. anyone want to answer this? T_T
Reply

Tags
calendar java time date