Conversion of string into date????????????

Can anyone tell how to convert a String into date??
if the string is in the format "Thu Mar 25 17:11:34 GMT+05:30 2004"
i have converted it. code is
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM d yyyy HH:mm:ss");
     dateFormat.setTimeZone(TimeZone.getTimeZone("GMT+00:00"));
Date date = null;
try
          //date = dateFormat.parse(new Date().toString());
          date = dateFormat.parse(dateLine);
     catch(ParseException ex)
but i am not able to specify the year.
so when i getYear on the new Date it return 1970.

@duffymo, I'm pretty sure "d" is good for a two digit date, "dd" gives you zero-padding.
The problem, presumably, is that the format string "EEE MMM d yyyy HH:mm:ss" does not match the actual format "Thu Mar 25 17:11:34 GMT+05:30 2004".
The correct format string would be "EEE MMM d HH:mm:ss z yyyy"

Similar Messages

  • Conversion of string into XML object

    Hi
    I am having some problems with conversion of string (containing XML data) into Flex XML object and binding it later to UI elements to output/maintain this data.
    Binding of XML structure to UI elements works perfectly fine if I will do following:
    1)      Hardcode XML object within Flex file
    2)      Read xml file from repository (xml file inside the Flex project)
    3)      Use HTTP request to retrieve XML data
    Unfortunately none of the above scenarios suits my solution.
    I am developing a prototype application for processing Flex forms inside SAP system. I have decided to make data bindings using XML structure stored in Data Base. When rendering form inside web browser based application I am retrieving corresponding XML schema (empty for new forms and populated for saved forms) and pass it to Flex form as a string type import parameter. Data is being passed correctly (I can display it on TextArea control for instance) but after conversion to XML and binding to DataGrid I am not getting any results.
    I am converting string (containing XML) to XML object in following way:
    Private var xml_obj:XML = new XML(string_xml );
    I am catching any potential errors but conversion is going well. After conversion I am not getting any results after binding it to DataGrid control and I am not able to access any of the nodes using AS code either. At the same time variable xml_obj is not empty (not null).
    Any help would be much appreciated.
    Regards
    Michael

    David
    First of all sorry for not stating it clearly but I am using Flex 3 for this development (at the moment it is the only choice when embedding Flex objects inside SAP applications).
    You must have missed the bit where I am describing how this XML data finds its way inside Flex. I am passing it to Flex as String type parameter during rendering (directly from DB where it is stored).
    Now, following code works perfect (XML is embedded inside Flex project):
                    <mx:XML id="form_data" source="../assets/example_xml_data.xml"/>
                    <mx:Script>
                                    <![CDATA[
                                                    import mx.collections.XMLListCollection;
                                                    import mx.controls.Alert;
                                                    [Bindable]
                                                    public var XML_list:XMLListCollection;
                                                    private function setParameters():void
                                                                   XML_list = new XMLListCollection(form_data.*);             
                                    ]]>
                    </mx:Script>
                    <mx:DataGrid id="myDataGrid" dataProvider="{XML_list}">
                                    <mx:columns>
                                                    <mx:DataGridColumn dataField="COMMON" headerText="Popular name"/>
                                                    <mx:DataGridColumn dataField="BOTANICAL" headerText="Botanical name"/>
                                                    <mx:DataGridColumn dataField="ZONE" headerText="Zone"/>
                                                    <mx:DataGridColumn dataField="LIGHT" headerText="Light"/>                                                                                                                                               
                                                    <mx:DataGridColumn dataField="PRICE" headerText="Price"/>                                               
                                                    <mx:DataGridColumn dataField="AVAILABILITY" headerText="Availability"/>                                    
                                    </mx:columns>               
                    </mx:DataGrid>
    But following code does not work (XML passed to Flex form as String input parameter):
    import sap.FlashIsland;
    import mx.controls.Alert;
    import mx.collections.XMLListCollection;
    [Bindable]
    public var xml_data:String;
    private var form_data:XML;
    [Bindable]
    private var XML_list:XMLListCollection;
    private function initApp():void
                    FlashIsland.register(this);
    private function setParameters():void
                    try
                                    form_data=new XML(xml_data);
                    catch (error:Error)
                                    Alert.show(error.toString());
                      XML_list = new XMLListCollection(form_data.*);           
    XML string does find its way inside Flex form. I can display content of variable xml_data in TextArea and all looks fine. Conversion to XML (variable form_data) goes well (no error)
    Please helpJ
    Regards
    Michael

  • String into date format

    Hi
    I was wondering if anyone knew how to convert a string into different formats,
    to enable it to be stored in a mysql db.
    I was wondering anyone you knew how to convert:
    - String into the date format yyyy-mm--dd
    - String into time format 00:00:00
    - string to double
    Ive tried:
    c_date = java.sql.Date.valueOf(f_date);
    System.out.println("conversion data: " +c_date);
    c_time = java.sql.Time.valueOf(f_time);
    System.out.println(" time converted data: "+c_time);
    // string to double conversion
    c_change = java.lang.Double.valueOf(f_change);
    System.out.println(c_change);
    My class doesnt execute this at all?
    Also,
    SimpleDateFormat sdft = new SimpleDateFormat("yyyy-MM-dd");
    c_date = sdft.format(f_date);
    System.out.println(c_date);
    .. but this method returns the error incompatible types?
    Any suggestions would be helpful.. thanks in advance..

    Friends i've got similar kind of problem...can you help me
    here is my code. When i try to print the user entered date (dd/MM/yyyy)(which i am storing in a string) the program dispalys nothing. and everey time i enter a valid date it displas "invalid From date entered ". I need to store the user entered date into a string because i need that for further use. All my intesion is to get two dates from user in dd/MM/yyyy. Strore them in certain variable. Check if they are valid or not. and make sure todate is either equal or greater than fromdate. Please help me to solve this problem.
    public class EDTDateValidation extends JFrame implements ActionListener{
    private JLabel fromlabel;
    private JLabel tolabel;
    private JTextField fromtxt;
    private JTextField totxt;
    private String fmt ="dd/MM/yyyy";
    private java.lang.String fromdate;
    private java.lang.String todate;
    private JButton buttonOK;
    private JButton buttonCancel;
    private Date theDate;
    private Date date1;
    private Date date2;
    private JPanel mainPanel;
    SimpleDateFormat dtformat = new SimpleDateFormat(fmt);
    public EDTDateValidation(){
    super("Date Validation");
    dtformat.setLenient(false);
    mainPanel=new JPanel();
    mainPanel.setLayout(null);
    fromlabel = new JLabel("From Date");
    tolabel = new JLabel("To Date");
    buttonOK = new JButton("OK");
    buttonCancel = new JButton("Cancel");
    fromdate = new String();
    todate = new String();
    fromtxt = new JTextField(10);
    totxt = new JTextField(10);
    fromdate = fromtxt.getText();
    todate = totxt.getText();
    mainPanel.add(fromlabel);
    fromlabel.setBounds(20,20,50,15);
    mainPanel.add(tolabel);
    tolabel.setBounds(20,50,50,15);
    mainPanel.add(fromtxt);
    fromtxt.setBounds(90,20,130,20);
    mainPanel.add(totxt);
    totxt. setBounds(90,50,130,20);
    mainPanel.add(buttonOK);
    buttonOK.setBounds(70,80,71,23);
    mainPanel.add(buttonCancel);
    buttonCancel.setBounds(150,80,71,23);
    buttonOK.addActionListener(this);
    buttonCancel.addActionListener(this);
    setContentPane(mainPanel);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(247,140);
    setResizable(false);
    //pack();
    public static void main(String args[]) {
    try {
    UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    catch(Exception e) {
    System.err.println("Could not load Look and Feel" + e);
    EDTDateValidation edtDateVal = new EDTDateValidation();
    edtDateVal.setVisible(true);
    public void actionPerformed(ActionEvent e) {
    if(e.getSource() == buttonOK){
    System.out.println(fromtxt.getText());
    System.out.println(fromdate); //THIS PRINTS BLANK
    System.out.println(todate); //THIS ASWELL
    try {
    Date date = null;
    date = dtformat.parse(fromdate);
    System.out.println("valid From date entered!");
    catch(Exception f) {
    System.out.println("Invalid From date entered!");
    // textField1.setText("");
    return;
    try {
    Date date = null;
    date = dtformat.parse(todate);
    System.out.println("valid TO date entered!");
    catch(Exception f) {
    System.out.println("Invalid To date entered!");
    // textField1.setText("");
    return;
    }

  • Regarding conversion of String to Date

    Hi
    Ravi here and I am getting the following exception when i am working with String to date conversion.As i am working in LAN this code is working for all others .This problem is with my system only.This is not supporting with yyyy-MM-dd format.One more thing in my system only we installed VisualStudio.Is that a problem for this exception.I am using Myeclipse
    Plzzzzzzzzzzz help me I got strucked .
    Thanks in advance
    Code:
    public void testSaveDates() throws HibernateException, ParseException{
    try{
    Date date=new Date();
    String str1 ="2006-05-06";
    Date dateFormatter = new SimpleDateFormat("yyyy'-'MM'-'dd").parse(str1);;
    System.out.println(dateFormatter);
    catch(Exception e){
    e.printStackTrace();
    Exception:
    java.text.ParseException: Unparseable date: "2006-05-06"
         at java.text.DateFormat.parse(DateFormat.java:335)
         at chaitanya.MyTest.testSaveDates(MyTest.java:282)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at junit.framework.TestCase.runTest(TestCase.java:154)
         at junit.framework.TestCase.runBare(TestCase.java:127)
         at junit.framework.TestResult$1.protect(TestResult.java:106)
         at junit.framework.TestResult.runProtected(TestResult.java:124)
         at junit.framework.TestResult.run(TestResult.java:109)
         at junit.framework.TestCase.run(TestCase.java:118)
         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)

    Date date=new Date();You don't need this line.
    Date dateFormatter = new
    er = new
    SimpleDateFormat("yyyy'-'MM'-'dd").parse(str1);;As already told, you don't need the single quotes. And you don't need two semi-colons - that's unnecessary.
    I just wrote a sample code to test that out. Check it and see for yourself.
    import java.text.SimpleDateFormat;
    public class Test {
         public static void main(String[] args) throws Exception {
              System.out.println(new SimpleDateFormat("yyyy-MM-dd").parse("2005-04-18"));
              System.out.println(new SimpleDateFormat("'yyyy'-'MM'-'dd'").parse("2005-04-18"));
    }Output:
    Mon Apr 18 00:00:00 EDT 2005
    Exception in thread "main" java.text.ParseException: Unparseable date: "2005-04-18"
            at java.text.DateFormat.parse(DateFormat.java:335)
            at Test.main(Test.java:6)I wonder why it is not feasible to write a quick sample code.

  • How to convert string into date

    Hi all,
    I m new to JDeveloper
    I m taking the date as a string then passing it as a string in the method.
    I want to convert tht string into the date of format (DD-MON-YYYY) or any other format
    require yur assistance in this job.
    THANKXX in advance
    ankit

    Is this what you are looking for:
    java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("dd-MMMMM-YYYY");          
    java.util.Date date1 = null;
    try
       date1 = formatter.parse("Thu Jun 3 09:09:30 2004");
    catch(Exception e)
       e.printStackTrace();
    System.out.println("Date1 in millis : " + date1.getTime());
    System.out.println("Date1 in string : " + date1);
    java.util.Date date2 = new java.util.Date(date1.getTime());
    System.out.println("Date2 in string : " + date2);or look at http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html for more options

  • Change string into Date?

    Hi guys
    I am writing a voice web application. My problem is when i speak the date it gets inserted into the textbox as a number e.g. 01012005 however when i pass this to my jsp then i get an error cause this not a valid date format.
    Can you help me change the number into a date e.g. insert / to split the day month and year up? so i can insert it into my database.
    Thanks

    You could use java.text.SimpleDateFormat to convert Strings to Date and back.
            SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyyy");
            Date d = sdf.parse("01012005");ram.

  • Insert string into date column

    I'm writing a bash script that is supposed to insert a series of strings into a table. Problem is I may not know which column the date is in, so I don't want to hard code a to_date function in there.
    For instance this row may come in to be inserted:
    "06-APR-10 08:51:12","data","data","data","data","data","data","data","data"
    Assuming the data is in the proper order, I'm just going to sub out the "," for ',' which will let me insert everything just fine, except obviously it borks on the date.
    How do I insert the date this way as a string using the default internal call to to_date?? I know I can do it with '06-APR-10' and it works, but I need to get a little more specific with hour minute and second.

    user12947249 wrote:
    I'm writing a bash script that is supposed to insert a series of strings into a table. Problem is I may not know which column the date is in, so I don't want to hard code a to_date function in there.If you don't know which string maps to which column, how do you expect to have any data reliability? Even if you manage to load the data without error, how can an application make any sense of it?
    I'm curious because if you have a method to map the columns, that could be used to help you (maybe) and if you don't have a method ... then i don't see this post as being your number one problem :)

  • HELP Conversion of string into SOAPMessage/SOAPPart

    I'm trying to convert a soap message that is stored in a String into a SOAPPart object, but I have some troubles.
    I thought this (code below) should work, but it gives a java.lang.ClassCastException at org.apache.axis.utils.XMLUtils.sourceToInputSource(XMLUtils.java:651)
    Can anyone help me, please??? Isn't there an easier way to convert a String into a SOAPPart?
    SOAPConnectionFactory scFactory = SOAPConnectionFactory.newInstance();
    MessageFactory factory = MessageFactory.newInstance();
    SOAPMessage message = factory.createMessage();
    SOAPPart soapPart = message.getSOAPPart();
    String input = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"......... etc
    DOMParser domParser = new DOMParser();
    Reader read = new StringReader(input);
    InputSource in = new InputSource();
    in.setCharacterStream(read);
    domParser.parse(in);
    Document doc = domParser.getDocument();
    DOMSource domSource = new DOMSource(doc);
    soapPart.setContent(domSource);                

    Why would you want to convert a String into a SOAPPart ?

  • How to convert string into date datatype

    hi! there
    i've a date in string format like MM/dd/yyyy
    eg:String sDate = "01/30/2002";
    and i want to convert this string format into java date format
    same as 01/30/2002 only
    when i write like this
    SimpleDateFormat formatter = new SimpleDateFormat ("MM/dd/yyyy");
              String sDate = "1/11/2002";
              java.util.Date oDate = formatter.parse(sDate);
    i'm getting the output
    Fri Jan 11 00:00:00 GMT+05:30 2002
    i just want the out put like 01/30/2002
    plz,help me

    Hi,
    Just use back the SimpleDateFormat object you defined.
    String myDateInStr = formatter.format(oDate);
    this will format a java.util.Date object to a string representation according to the format you specified in the instantiation of SimpleDateFormat object.

  • Conversion of String to date

    Hello,
    I have a date in String format like "01/03/2006"
    How can I get "Mar-2006" in java?
    Please Help

    have a look at that:
    http://www.javaworld.com/jw-12-2000/jw-1229-dates.html
    regards.

  • Conversion of string to data(Flat file to sql server) Transformations

    Hi All,
    I have a requirement in which I am trying to convert a field of type string which contains date from source file to field of type datetime in sqlserver by using all the below expressions
    to_date(DATE, 'yyyy/mm/dd-hh24:mi:ss' )
    to_date(DATE, 'yyyy/mm/dd' )
    However it is not throwing any errors but the data of the date field is being loaded with null values(Date is present in flat file).
    Any inputs plz???
    Thanks
    U

    Can you post a sample of the date string you are trying to convert?

  • Converting a string into Date format

    I am currently using a JSP.
    I currently need to convert a string that holds a date in "dd/mm/yyyy" format to the jva.sql.Date format.
    Any ideas as to what the proper way of doing this is?
    Many thanks ppl

    public java.sql.Date parseDate(String s) {
         java.text.DateFormat dateFormatter= new java.text.SimpleDateFormat("dd/MM/yyyy");
         return new java.sql.Date(dateFormatter.parse(s).getTime());

  • Conversion from string to Date Query.

    Hi,
    I need a way to convert a date format which is in string to a date data type.
    String is in the following format : Tue Feb 27 16:00:31 PST 2007
    Have used the SimpleDateFormat class but it returns an unparseble data error.
    Any thoughts????
    Regards
    Sam W

    Please don't crosspost: http://forum.java.sun.com/thread.jspa?threadID=5142482

  • Converting string into date

    How can I convert a string 07-27-2001 in a date.

    How can I convert a string 07-27-2001 in a date.
    one of the solutions might be --
    SimpleDateFormat format = new SimpleDateFormat ("MM-dd-yyyy");
    Date date = format.parse("07-27-2001");

  • Change "String" into data type "Date"

    Hi,
    I have created a report containing several date fields for a plan/actual comparison. The connection is built up by using the jdbc connector.
    My problem is that the date fields are only displayed as String, but I actually want them to be displayed as Date type.
    Here an example:
    Right now the date fields are displayed like this "20060411"
    but I want them to be displayed like this ("11/04/2006", or similar).
    I would appreciate any suggestions to solve this problem!
    Cheers
    Thomas

    Hi Thomas,
    Check out the following links :
    http://help.sap.com/saphelp_nw04/helpdata/en/55/55a34098022a54e10000000a1550b0/content.htm
    http://help.sap.com/download/netweaver/nw04/visualcomposer/VC_60_UserGuide_v1_1.pdf
    Re: Custom message in VC
    Thanks in advance,
    Deep.

Maybe you are looking for

  • How do i copy contacts from my iphone 3gs to iphone 5s

    how do i transfer contacts from iphone 3gs to iphone 5s

  • XI Implementation

    Hi XI Gurus, We are a retail company, we have newly bought SALESFORCE.com for our CRM process. We plan to integrate it to our SAP R/3 system. We are trying to decide what sort of integration tool would be best suitable, including XI. So would appreci

  • Accessing a loaded swf

    I'm using this code to bring in another swf into a movieClip called "movieLoader": var myLoader:Loader = new Loader(); movieLoader.addChild(myLoader); var urlMovie:URLRequest = new URLRequest("movie1.swf"); myLoader.load(urlMovie); The movie loads ju

  • Computer on wireless cannot log onto domain but if i change name it works.

    I have an XP machine that can not log onto a 2003 domain with the a certain name. I have narrowed it down to the name and on wireless. If i put this on the wire it works fine and if i change the name it works fine on wireless. Due to our naming conve

  • How can i find Photoshop to edit my own image?

    How can I find Photoshop to edit my own image? I have seen a lot of learning videos,