How to parse string to date in j2me?

How to parse string to date in j2me?
Please help me.

Hi..
String dyStr = "20";
String mtStr = "1";
String yrStr = "1999";
Calendar cal = Calendar.getIntstance();
int dy = Integer.parseInt(dyStr);
int mt = Integer.parseInt(mtStr);
int yr = Integer.parseInt(yrStr);
cal.set(Calendar.DATE, dy);
cal.set(Calendar.MONTH, mt);
cal.set(Calendar.YEAR, yr);
OK?

Similar Messages

  • How to parse string to date with defualt format?

    is there any possibilities to parse a string to date if we don't specify the format in SDF?
    In database we have different formats and we need to convert each one convert to date with common format(something like default), is there any possibilities to do in java?

    jwenting wrote:
    Tolls wrote:
    ColinAtWork wrote:
    SumantK wrote:
    In database we have different formats and we need to convert each one convert to date with common format(something like default), is there any possibilities to do in java?Why don't you store the date in the database as a DATE datatype then you can format anyway you like??Because some people seem to fear DATEs and prefer the supposed comforts of a VARCHAR2...after all, who knows what murky goings on occur with a DATE, but at least a VARCHAR2 is readable, or something like that anyway.Just because some people don't know how to work with DATE fields (which is the real reason for their "fear" doesn't mean you shouldn't use them.
    They're the appopriate solution, so use it.Often but not always true.
    For example neither MS SQL Server nor Oracle timestamp types will store the resolution capable with the Java Date type. So if one wants to maintain all of that resolution one requires either a varchar or two columns.
    And although I haven't been able to confirm it (recently at least) at one time one of the Oracle drivers had a bug that a timestamp would wipe out following columns. For that one either one was left with having only a single timestamp as the last column or using a varchar.

  • How to parse thus XML data?

    Hi,experts:
    In below thread:
    Receiving .Net dataset with deployed proxies
    i asked how to create a external definition in IR base on above XML data.
    Now,i have created a XSD file base on the XML data.And importing it into IR successfully.
    <?xml version="1.0" encoding="utf-8"?>
    <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:Locale="zh-CN">
    <xs:complexType>
    <xs:choice maxOccurs="unbounded">
    <xs:element name="Status">
    <xs:complexType>
    <xs:attribute name="Result" type="xs:string"/>
    </xs:complexType>
    </xs:element>
    </xs:choice>
    </xs:complexType>
    </xs:element>
    </xs:schema>
    And now,the question is how to parse the XML data in diffgr:diffgram  segment.It seems a MS-XML syntax.Can it be parsed by XI?
    I tried,but the following error occurs:
    com.sap.aii.utilxi.misc.api.BaseRuntimeException: RuntimeException in Message-Mapping transformation: Cannot produce target element /ns0:ZMT_SD_ORDER01_RESULT. Check xml instance is valid for source xsd and target-field mapping fulfills requirements of target xsd at com.sap.aii.mappingtool.tf3.AMappingProgram.start

    Hi,
    The above Exception seems to be because of mapping error.
    Check your mapping for all the mandatory 1-1 mapping, also the 1-unbounded parent node mapping.
    Once when you import the XSD and activate your External Definition if it does without any error then there is no problem with your External Definition.
    If this error occurs only when you test your mapping then this is mapping error and not because of XSD.
    Please check the parent node mapping like 1-unbounded.
    Reward Points if useful
    Regards
    Ashmi.

  • How to convert string to date based on regional settings

    How can I convert a simple string ("01/04/2003" or "01-04-2003" or "01 April 2003") to a date formatted according to the regional settings?
    For example, if my regional settings is set to "dd mm yyyy", the result will be 01 as dd, 04 as mm and 2003 as yyyy.
    If the regional settings is set to "mm dd yyyy", the result will be 01 as mm, 04 as dd and 2003 as yyyy
    Hope someone can help.
    Thanks in advance.

    I think you have the wrong idea about how Oracle stores dates. Any date in Oracle is stored in a seven byte representation
    SQL> SELECT DUMP(last_hire_dt) FROM emp_t WHERE rownum = 1;
    DUMP(LAST_HIRE_DT)
    Typ=12 Len=7: 119,191,5,6,1,1,1This storage is independent of the NLS date settings. The TO_CHAR(dt,format) and TO_DATE(str,format) functions serve to translate this internal representation into the external presentation supplied by the format. So, if you need to translate a date that is contained in a string into an Oracle date datatype, you need to tell Oracle how to parse the string.
    If the string format matches your NLS_DATE_FORMAT parameter, Oracle will do this implicitly. Otherwise, you need to tell Oracle explicitly which piece is which. For example, is the string (ignoring the problem of two digit years :-) ):
    '02/01/03'
    Feb. 1, 2003, Jan. 2, 2003, or Mar. 1, 2002? If your date format is dd-MON-yyyy as mine is, then:
    SQL> SELECT TO_DATE('02/01/03') FROM dual;
    SELECT TO_DATE('02/01/03') FROM dual
    ERROR at line 1:
    ORA-01843: not a valid month
    SQL> SELECT TO_DATE('30-Jan-2003') FROM dual;
    TO_DATE('30
    30-JAN-2003HTH
    John

  • SimpleDateFormat: Parse String To Date

    Hi
    I'm trying to parse Date-String to Date. But the Date-String I want to parse is embedded in a Text like:
    Bla bla bla bla bla bla 2004-05-05 bla bla bla bla bla.
    So I tried the attached Class to solve the problem, but it didn't work.
    Any ideas?
    Thanks Bona
    public class Test {
    private static SimpleDateFormat dateFormat = new SimpleDateFormat();
    private String text;
    private Date date;
    public Test() {
    /ry {
    text = "Bla bla bla bla bla bla 2004-05-05 bla bla bla bla bla.";
    date = toDate(text, "yyyy-MM-dd");
    System.out.println("Datum: "+date);
    } catch (ParseException pe) {
    System.out.println(pe.getMessage());
    public static void main(String[] args) {
    Test test1 = new Test();
    public static Date toDate(String dateString, String dateFormatPattern)
    throws ParseException {
    Date date = null;
    dateFormat.applyPattern(dateFormatPattern);
    dateFormat.setLenient(true);
    date = dateFormat.parse(dateString);
    return date;
    }

    Well, you need to extract the date pattern from that String.
    You can use regular expressions to do that. See theRegex package for info on how to do that.
    BTW - AFAIK, lenient date parsing means, that the parser accepts stuff that matches the pattern, but contains illegal values like "2004-02-30" ...

  • Any easy way to parse string to date?

    I need get data from process instance and pass it to web service.
    The process instance is xmlObject and one field is date type. The value read from xmlObject is "2011-09-13T20:10:00Z"
    Is there any easy way to convert it to Date?
    Thanks,

    Hi
    Use date format to convert the string to date
    Example:
    String dateString = "Nov 4, 2003 8:14 PM";
    DateFormat format = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT);
    Java.Util.Date date = format.parse(dateString);
    display("Formated Date: " + date);
    Bibhu

  • Parsing String to date

    This is my function to convert a string into a desired output format.But my Date in the desired output format is coming out to be null.Could smeone plz point out my mistake.
    Date getDateInDesiredFormat(String strInputDate,String strInputFormat,String strOutputFormat)
         try
           SimpleDateFormat sdfInput  = new SimpleDateFormat(strInputFormat);
           SimpleDateFormat sdfOutput = new SimpleDateFormat("MM-dd-yyyy");
           ParsePosition pos = new ParsePosition(0);
           Date dtInputDate=sdfInput.parse(strInputDate.trim(),pos);
           System.out.println(dtInputDate);
           String strFormattedDate=sdfOutput.format(dtInputDate);
           System.out.println(strFormattedDate);
           Date dtOutputDate=sdfOutput.parse(strFormattedDate.trim(),pos);
           if(dtOutputDate==null)
                System.out.println("dtOutputDate is null ");
           else
               System.out.println(dtOutputDate.toString());
           return dtOutputDate;
         catch (NullPointerException npex)
             return null;
          catch(Exception ex)
              return null;
       }This is how i am calling the function
    Date date=getDateInDesiredFormat("Fri Sep 30 20:30:56 IST 2006","EE MMM d HH:mm:ss ZZZ yyyy","MM-dd-yyyy");
      }

    You need to use the sdfInput object to parse the date and sdfOutput to format and print it (like you did before your 'if'):
    SimpleDateFormat sdfInput  = new SimpleDateFormat(strInputFormat);
    SimpleDateFormat sdfOutput = new SimpleDateFormat("MM-dd-yyyy");
    Date dtInputDate=sdfInput.parse(strInputDate.trim());
    String strFormattedDate=sdfOutput.format(dtInputDate);
    System.out.println(strFormattedDate);the toString() you use in the else block uses a default format, not the one you specify.

  • How to convert String to date ? - MS access

    I want to convert a string "10-10-08" [ MM-dd-yy ] into date type in same format to use that in query statement [MS Access].
    In table , I am using field called "date" with "MM-dd-yy" format.
    Example:
    <%@ page import= "java.sql.*"%>
    <%@ page import="java.text.SimpleDateFormat"%>
    <%@ page import="java.util.Date"%>
    <%
    String d="10-9-08";
         SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd-yy");
              Date date = dateFormat.parse(d);
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
         Connection con = DriverManager.getConnection("jdbc:odbc:bspipdb");
         Statement st = con.createStatement();
    ResultSet rs=st.executeQuery("Select * from datacollectdb where date='"+date+"'");
    %>
    I am getting "java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.
    " error.
    How to use the string "10-10-08" in where statement?

    sangee wrote:
    I want to convert a string "10-10-08" [ MM-dd-yy ] into date type in same format to use that in query statement [MS Access].
    In table , I am using field called "date" with "MM-dd-yy" format.I think a column named "date" is a very bad idea. Not just because "date" is a keyword. It's not very self-describing. How about "birth_date" or "hire_date" or "went_on_my_first_date"?
    Example:Scriptlets? There's your second mistake.
    <%@ page import= "java.sql.*"%>
    <%@ page import="java.text.SimpleDateFormat"%>
    <%@ page import="java.util.Date"%>
    <%
    String d="10-9-08";The way you're doing things, "2-40-99" is a valid date. Is that what you want?
         SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd-yy");
              Date date = dateFormat.parse(d);
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
         Connection con = DriverManager.getConnection("jdbc:odbc:bspipdb");Wrong again. Better to use a PreparedStatement and bind that Date.
         Statement st = con.createStatement();
    ResultSet rs=st.executeQuery("Select * from datacollectdb where date='"+date+"'");
    %>
    I am getting "java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.
    " error.
    How to use the string "10-10-08" in where statement?Use PreparedStatement and bind.
    Your JSP should not be getting a database connection. Pool it.
    Your code is wrong on every level. You don't close resources, you don't separate you app into layers, your database code is not in a POJO. I'd recommend that you throw this away and start again.
    %

  • How to change String to Date

    Hi All
    How to change Java String to Java Date
    thanks in advance
    by
    mahender

    import java.text.*;
    import java.util.Date;
    class dateparsing{
         public static void main (String args[]){
              String myString ="12/10/2001";
              DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
              ParsePosition pos = new ParsePosition (0);
              Date myDate = df.parse(myString,pos);
              System.out.println(myDate.toString());
    }import java.text.*;
    import java.util.Date;
    class dateparsing{
         public static void main (String args[]){
              String myString ="12/10/2001";
              DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
              ParsePosition pos = new ParsePosition (0);
              Date myDate = df.parse(myString,pos);
              System.out.println(myDate.toString());
    }

  • How to convert string to date

    HI Everyone,
    i am trying to convert a date which is in string format to a date format...but i am having this error
    javax.servlet.ServletException: Unparseable date: "2004-05-03"
    Can anyone help?
    Here is a piece of code :-
    SimpleDateFormat formatter= new SimpleDateFormat ("yyyy-mm-dd");
    Date today = formatter.parse(fulldate);

    You need to change your formatting string to: "yyyy-MM-dd" Lower case 'm' is for minutes...

  • 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.

  • 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

  • How to parse all the data of the particular tag in the xml file

    Hi All,
    I have a xml file, which have tags like, code,rev_num,type...volunteer.I want to parse the xml and save the all data(code,rev_num...) of the tag <type>unknown </type>in a text file. I tried to use a Match node vi but I not geting the output i need.attach is my attempt , can anyone suggest me or help me out.(Sorry Cant attach the xml hence i saved it as an text file.)
    Thanks,
    Ankit G
    Solved!
    Go to Solution.
    Attachments:
    teeth.txt ‏385 KB
    Xml parse.vi ‏22 KB

    TailOfGon wrote:
    Do you want to extract all the data with type='unknown'?
    Then try the XPath like this: 
    resource[type='unknown']/code
    Hi,
    Yes I want to extract all the data of the type = "unknown", I tried Xpath resource[type='unknown']/code but it didnt work , I still getting all other data of different type .
    Thanks,
    Ankit G

  • How to parse BEX Query data to Flex interface via XML

    Hi,
    How can we pass the Bex Query data in XML tabular format so it can be consumed by a Flex interface?
    And communicate back and forth.
    Regards
    Vivek

    Hi,
    May be this link is helpful to you,
    http://help.sap.com/saphelpnw04/helpdata/en/d9/ed8c3c59021315e10000000a114084/frameset.htm_
    All the Best,
    Madhu....

  • How to convert string to date and check date difference in filter clause | error in filter clause

    Hi All,
    I have a requirement where i want to stop replicat if particular record is encountered on target.
    if PARAMETER_CODE="APPLDATE" and difference between parameter_value is 1 then replicat should stop.
    the code i am using is,
    map schema.src_tablename , target schema.trg_tablename, &
    WHERE(PARAMETER_CODE="APPLDATE"), &
    filter (on updates, (@to_date(before.PARAMETER_VALUE,'dd/mm/yyyy hh24:mi:ss')) - (@to_date(PARAMETER_VALUE,'dd/mm/yyyy hh24:mi:ss')) =1), &
    EVENTACTIONS(STOP);
    Replicat process abends with error in filter clause.
    Concern here is the parameter_value column is in varchar2 and not in date. (if its date than filter (on updates, @datediff ("DD",before.PARAMETER_VALUE, PARAMETER_VALUE) =1)  is working correctly). I need to stop replicat when date(in varchar2 format) gets incremented by 1.
    Please do help in solving the issue.
    Thanks,
    TrushB.

    Dear all,
    Please do update... how to covert a varchar2 to date in GG.

Maybe you are looking for