Loading
Convert String to Calendar

Java Quick Notes

Refresh Your Java - Before Java Interview

We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....


Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet

Go to SiteMap

Q)  Convert String to Calendar


Ans)


"Convert Date To Calender","Convert SQL Date To Calendar","Convert String to Calendar",
"Convert Calendar to String"

This Util Class Holds the methods for following purposes.

i) Convert Date To Calender
ii) Convert SQL Date To Calendar
iii) Convert String to Calendar
iv) Convert Calendar to String

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.StringTokenizer;

public class CalendarUtil {

    public static Calendar convertDateIntoCal(Date date){
     Calendar cal = Calendar.getInstance();
     cal.setTime(date);
     return cal;
    }
   
   
    public static Calendar convertSQLDateIntoCal(java.sql.Date date){
     Calendar cal = Calendar.getInstance();
     cal.setTime(date);
     return cal;
    }
   
  
    public static Calendar convertStrIntoCal(String strDate){
     Date date = null;
     Calendar cal = Calendar.getInstance();
     SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
     try{
      date = dateFormat.parse(strDate.trim());
     }catch (Exception e){
      e.printStackTrace();
     }
     cal.setTime(date);
     return cal;
    }
   
    public static String convertCalIntoStr(Calendar cal){
     return (cal.get(Calendar.MONTH)+1)+"/"+cal.get(Calendar.DATE)+"/"+cal.get(Calendar.YEAR);
    }
}



Back to top

------------------------- We hope you got necessary Info On -----------------------------------------

Convert String to Calendar


Convert String to Calendar

-------------------------------------------------------------------------------------------------------



Face Book
Request for a Mock Interview/Training

Get a PDF

Face Book
Same look (Read) on any device, this is Ads free