Converting String to Calendar Object

Hi,
I nedd to Change the below String to Calendar Object.i want to show the records which are older than half an hour.any other idea which will solve my problems?
Fri Aug 17 01:56:40 GMT+05:30 1906
Thanks in advance.
Regards:
Akash.

Look at
java.text.SimpleDataFormat

Similar Messages

  • Convertion string to Calender object

    The input string format is "hh-mm-ss". How can I convert to Calender object.
    Can anybody suggest ?
    Thanks
    Pravat

    Use a java.text.SimpleDateFormat to convert the string to a java.util.Date object and then set the calendar object from that.

  • Convert string to  calendar

    bail me out of this problem
    i got 3 "Calendar" objects : "to" , "from" and "now"
    i got another Sting Object "n"
    where String n = now.toString()
    I have access to "to", "from" and "n"
    and I have to know whether n lies in between "to" and "from"
    The following code does not give right answer
    if(from.before(n) && to.after(n))
    System.out.println("n lies between to and from");
    help me out...

    Create a suitable SimpleDateFormat object and use it to convert your string to a java.util.Date before making the test.
    You probably want Date objects, not Calendar objects. Calendar objects are for doing date calculations - like adding a month to a date or whatever.

  • Converting String to an Object of a class

    Hi all,
    I want to convert a string to an object of a class.
    Please see my below code:
    MyClass rahul = null;
    String data = "DATA";
    rahul = (MyClass) data;
    I am getting the error: Invalid cast from java.lang.String to MyClass
    Please help me as its urgent

    There is no magical String deserialization in java. If your class can convert it's state to a string, then you will need to write the reverse parsing code, presumably using either a constructor which takes a string, or a static method similar to how numbers are handled, like:
    MyClass c = MyClass.valueOf(data);Obviously, in either case you will need to write the code to do this.

  • Converting Strings to Color Objects

    Greetings All -
    I'm in my first Java class (I was a C programmer in the 80s!) and am a little stumped on an assigment. Your help will be much appreciated.
    I have to read color strings out of an HTML file and put them in a HashMap (a small applet assignment). I've been unable to find an elegant method for converting from a string to a color object.
    Please let me know if I'm stuck with a big nested if or am I overlooking something?
    Thank you -
    Gargoyle

    This will handle #rrggbb strings, and also the dozen or so colors defined by name (red, cyan, etc) in the static fields of java.awt.Color:
    static Color stringToColor (String s)
         try {
              return Color.decode(s);
         } catch (Exception e) {}
         try {
              return (Color) Color.class.getField(s).get(null);
         } catch (Exception e) {}
         System.out.println("bad color string: " + s);
         return null;
    }

  • Issue with converting string to date object

    Hi all,
    I have a problem with sorting a list of dates in a table column. My dates are in the format 'yyyy-Mmm-dd'(Eg: 2009-Dec-23). Can someone help me how to sort the dates in this format. here is the code which i tried.
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-Mmm-dd");
              Date d1= new Date();
              Date d2= new Date();
              try {
                   d1 = dateFormat.parse("2006-Jun-09");
                 d2 = dateFormat.parse("2006-Apr-10");
              } catch (ParseException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              System.out.println("converted date 1"+ d1);
             System.out.println("converted date 1"+ d2);
    Exception : Unparseable date: "2006-Jun-09"
         }Please someone help me how to pass this date in the right format.

    I believe twisai may have lost the documentation so he/she can figure this out rather than guess that "Mmm" means 3-letter month, first letter capitalized. Let me remind him of the link:
    [http://java.sun.com/javase/6/docs/api/index.html]

  • String to xml object java

    Hello,
    can anyone suggest me how to convert string to xml object in java?
    I have a string (Data) ant now I have to pass it as parameter as xml object, which structure should be:
    <MGWData>Data</MGWData>
    Where I surf I always see only solutions for converting string to xml document, but never to xml object.
    maybe the problem is I don't completely understand what xml object is in first place :/
    Any answer would help.
    Thanks.

    894871 wrote:
    here is the method to call:
    +/**+
    * Sets the p_DATAXMLTYPEIN value for this SVARCHAR2INSERT_RECEIVESInput.
    *+
    * @param p_DATAXMLTYPEIN
    *public void setP_DATAXMLTYPEIN(com.oracle.xmlns.orawsv.SISTEMA_MOKA.MGW_PUBLIC_FUNCTIONS.SVARCHAR2INSERT_RECEIVESInputP_DATAXMLTYPEIN p_DATAXMLTYPEIN) {*
    this.p_DATAXMLTYPEIN = p_DATAXMLTYPEIN;
    one of the classes contains:
    *public class SVARCHAR2INSERT_RECEIVESInputP_DATAXMLTYPEIN  implements java.io.Serializable, org.apache.axis.encoding.AnyContentType {*
    *private org.apache.axis.message.MessageElement [] _any;*
    this method and some classes where generated using eclipse and wsdl file by creating web service client.
    wsdl says for that part: *<xsd:element name="P_DATA-XMLTYPE-IN">*
    So I suppose it should involve smth org.apache.axis.message.MessageElement. But when I create any type of parameter, it gives me error:
    + ....cannot be cast to com.oracle.xmlns.orawsv.SISTEMA_MOKA.MGW_PUBLIC_FUNCTIONS.SVARCHAR2INSERT_RECEIVESInputP_DATAXMLTYPEIN+
    I am new in web service stuff so thank you for response.Can you explain in plain English what you are trying to do? Or provide a [url http://sscce.org/]SSCE.

  • Need to convert  Date from calendar to String in the format dd-mom-yyyy

    Need to convert Date from calendar to String in the format dd-mom-yyyy+..
    This is absolutely necessary... any help plz..
    Rgds
    Arwinder

    Look up the SimpleDateFormat class: http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html
    Arwinder wrote:
    This is absolutely necessary... any help plz..For you maybe, not others. Please refrain from trying to urge others to answer your queries. They'll do it at their own pace ( if at all ).
    People on the forum help others voluntarily, it's not their job.
    Help them help you.
    Learn how to ask questions first: http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch
    (Yes I know it's on JavaRanch but I think it applies everywhere)
    ----------------------------------------------------------------

  • How can I convert a string to an object or class

    I would like to read a file representing a class, and convert it to an object or a class (object preferred). Other postings suggest using javax.tools.JavaCompiler to convert from a string but then say that this is not always available (posting on 1 Jan 09). If this is still not universally available is there another way to do this? If this is not available, are there any examples of how it should be done?
    My understanding from what I've read is to read the file into a String then compile the String using javax.tools.JavaCompiler, which is an Interface.
    thanks

    skidmarks wrote:
    What i would like to do is to take a Java file representing a class and compile it at runtime. However, the comment about a JDK being available at runtime makes this unattractive.So, you want to compile .java files, but you don't want to have to use a compiler?
    The next guess would to be to create a .jar file and reference it at runtime. Here's the scenario:Eh? How is that even remotely equivalent?
    1. People using the 'system' will have a varied knowledge of Java.
    2. My hope was to require that anyone using the program would only need to create a Java Class file,You mean a Java source file. You have said that YOU want to create the .class file. If they are creating the .class file, then all you need to do is load it with a ClassLoader and start using it.
    You might try clarifying your requirements a bit.
    In either case, the Class Files would look like:
    public class Name {
    int field1;
    float field2;
    } With all the field types being simple Java Primitives.What is the point of this? What are you ultimately trying to accomplish, that can be served by user-defined groups of primitives, with no complex object graphs and no user-defined methods?
    Depending on what you're really getting at, using scripting features via beanshell, groovy, or javascript might be an approach to consider, or using Scala to produce a domain-specific language (although I suspect that last may be overkill, and beyond your current skill level).
    If this is so, is there any way to create a .jar file at runtime? Do I have to exec("jar") or is there another way.A .jar file is just a .zip file with a manifest. Look at the java.util.jar package. But note that creating a .jar file has nothing to do with the rest of what you're asking about.

  • Convert String variable value  to an Object referece type

    Hi all,
    I want to know that if there any possible way to convert String variable value to a Object reference type in java. I'll explain by example if this is not clear.
    Let's think that there is a string variable name like,
    String name="HelloWorld";
    and there is a class name same to the variable value.
    class HelloWorld
    I am passing this string variable value to a method which is going to make a object of helloworld;
    new convertobj().convert("HelloWorld");
    class convertobj{
    public void convert(String name){
    // in hert it is going to create the object of HelloWorld;
    // HelloWorld hello=new HelloWorld(); just like this.
    now i want to do this from the name variable value.( name na=new name()) like wise.
    please let me know if there any possible way to do that.
    I am just passing the name of class by string variable then i wanted to make a instance of the class which come through the variable value.
    thanx.

    Either cast the object to a HelloWorld or use the reflection API (Google it) - with the reflection API you can discover what methods are available.
    Note: if you are planning to pass in various string arguments and instantiate a class which you expect to have a certain method... you should define an interface and have all of your classes that you will call in this way implement the interface (that way you're sure the class has a method of that name). You can then just cast the object to the interface type and call the method.
    John

  • Convert a calendar object to a date object

    hi all...i use a calendar to select date and i want to convert the Calendar object returned to a date object ..how could i do that ?? i use the following lines of code but the Date object returned is not correct ..i mean it's not the one i chose from the calendar
    Date selectedDate=new Date();
    selectedDate=(calendar1.getTime());
    Any one could help....thank you

    Show us the code where you set the calendar to your desired value. Calendar1.getTime()
    should return the relevant date.

  • Converting a String to Calendar

    I have a String which is actually a date in the format yyyyMMdd.
    I need to take this String and convert it into a Calendar to do a before() check.
    I want to delete dates prior to a certain date.
    I am able to use this code to get a String to a Date but I need a String to a Calendar.
    String sDateOfDir = null;
    sDateOfDir = children;                              
    Date dStringToDate = (Date)sdf.parse(sDateOfDir);      
    Calendar cal = Calendar.getInstance();
    cal.setTime(dStringToDate); // this is still java.util.Date
    I need a String to a Calendar
    or
    can this line of code
    cal.setTime(dStringToDate); be formatted to yyyyMMdd
    any suggestions thanks in advance

    I dont know what I am having such a block today. I am not sure I understand. I have posted my code and I hope you can just point out how I can make this easier.
    I am reading in a File Directory with its subfolders.
    The subdirs are named with the Date the subdir is created (yyyyMMdd)
    I want to delete the subdirs that are older than 30days
    public class RemoveFileFolders
         public static String sDirDNE = "Either dir DNE or is not a dir";
         public static String sSuccessFalse = "!success false";
         public static String sNowDeleting = "Now deleting contents of ";
         public static String sForSub = " for subdir(s) prior to ";
         public static java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyyMMdd");
         public static void main(String[] args)
              File fDir = new File("\\C:\\Dates");
              Calendar cTodayMinusOneMonth = Calendar.getInstance(); //today
              cTodayMinusOneMonth.roll(Calendar.MONTH, false); //today minus one (1) month
              //I want to delete all subdir that are older than 20070821
              System.out.println(sNowDeleting + fDir + sForSub + sdf.format(cTodayMinusOneMonth.getTime()));
              //String sCalToString = null;
              //sCalToString = sdf.format(cTodayMinusOneMonth.getTime()).toString();
              if(fDir.isDirectory())
                   String[] children = fDir.list();     
                   if (children == null)
                        System.out.println(sDirDNE);
                   else
                        try
                             for (int i = 0; i < children.length; i++)
                                  String sDateOfDir = null;
                                  sDateOfDir = children;
                                  Date dStringToDate = (Date)sdf.parse(sDateOfDir);
                                  System.out.println("sDateOfDir I am a string " + sDateOfDir);
                                  Calendar cal = Calendar.getInstance();
                                  //cal.setTime(dStringToDate);
                                  cal.before(dStringToDate);
                                  //if DateDir is before cTodayMinusOneMonth.roll(Calendar.MONTH, false); //today minus one (1) month
                                  //delete that dir
                                  if(children[i].equalsIgnoreCase(sDateOfDir))
                                       boolean success = deleteDir(new File(fDir, children[i]));
                                       if (!success)
                                            System.out.println(sSuccessFalse);
                        catch(ParseException pe)
                             System.out.println("ParseException " + pe);
         public static boolean deleteDir(File fDir)
              if (fDir.isDirectory())
                   String[] children = fDir.list();
                   for (int i = 0; i < children.length; i++)
                        boolean success = deleteDir(new File(fDir, children[i]));
                        if (!success)
                             return false;
              return fDir.delete();

  • How to convert a String to Calendar ?

    Hello all,
    I need to convert a date which is in the form dd-mon-yyyy to a Calendar. Can any one help me ?. This is my first post here.

    And an example:import java.text.*;
    import java.util.*;
    public class Test {
        public static void main (String[] parameters) {
            try {
                System.out.println (getDate (getCalendar ("17 jun 2003", "dd MMM yyyy"), "d MMMM yyyy"));
            } catch (ParseException exception) {
                exception.printStackTrace (System.err);
                System.exit (- 1);
        private static Calendar getCalendar (String date, String format) throws ParseException {
            Calendar calendar = new GregorianCalendar ();
            calendar.setTime (new SimpleDateFormat (format).parse (date));
            return calendar;
        private static String getDate (Calendar calendar, String format) {
            return new SimpleDateFormat (format).format (calendar.getTime ());
    }Kind regards,
      Levi

  • How to convert a string to date object?

    I have a string user input for date.
    I want to convert it to Date object to insert it in database.
    How to do it?

    Check the java.text.SimpleDateFormat class. You can use it for parsing dates. API contains good description how to build the format pattern.
    HTH
    Mike

  • Convert Date Object to Calendar object

    Hi,
    I have a Date field in my webdynpro application, I need to to read this from my current context and convert the same to a Calendar field and pass it to my model.
    Calendar date = CalendarConverter.parseDate(req_date.toString());
    The above code gives me a null pointer exception.
    Can anyone suggest me the right way of converting a Date object to Calendar object?
    Ashwini.

    Ashwini,
    try to use the following code snippet:
    // get calendar and set your date object
    Calendar c = Calendar.getInstance();
    c.setTime( <YOUR_DATE_OBJECT> );
    // to manipulate the fields use this
    c.set(Calendar.MONTH, 1);
    // to manipulate retrieve a fields use this
    c.get(Calendar.MONTH);
    Hope that helps you.
    Sebastian Voss

Maybe you are looking for