How to cast a String input into Date variable?

I am using JOptionPane.showInputDialog to ask user for a date input. This will be read in as a String. I need to pass it to a variable call date. And when I print date using JOptionPane, it should be shown as whatever the user keyed in in this format: 25/2/09. How do I do it?

By the way, that's not casting. Casting is when you have a variable whose type is at a particular level of detail, and you assign it a different level of detail -- say, casting an int to a long, or a List to an ArrayList.
What you want to do is convert one type to a completely different one. In particular, you're going to do that by using SimpleDateFormat to parse the String -- that is, SimpleDateFormat will read the string, pick out the individual parts that express the date, and create a Date object that corresponds to it.

Similar Messages

  • How to get a string "yyyyMMdd" into date like MM/dd/yyyy?.

    Hi
    How to get a string "yyyyMMdd" into date like MM/dd/yyyy?. i have used
    SimpleDateFormat.parse but it is giving long value. i want to disply the date
    like MM/dd/yyyy
    thank you

    Do you want the string rearranged or do you want to create an instance of some form of Date class?
    If you want to rearrange the string you could just do it yourself provided you know the date string is going to be of the format yyyyMMdd.
    something like this:
    String newDate = origStr.charAt(4) + origStr.charAt(5) + "/" + origStr.charAt(6) + origStr.charAt(7) + "/" ...etc.

  • I loaded my ipad photos from camera and all the pictures sorted by date.  Next, I did a sync with my computer and the photos were all reorganized into IMPRT folders an out of date sequence.  Any idea how to put the photos back into date files?

    I loaded my ipad photos from camera and all the pictures sorted by date.  I later sync my ipad with my computer and the photos were all reorganized into IMPRT folders an out of date sequence.  Any idea how to put the photos back into date files other than reloading all of them from camera?

    What version of iPhoto?
    Select one and rotate it. Then rotate it back. Does that make it appear? 
    A much better work flow is the keep the photos after importing.  Check the success the import, wait for at least one successful backup cycle then use you camera's format command to reformat the card
    LN

  • String conversion into Date

    How do I cast a String into a java.util.Date

    Thank you.
    I did it as following:
    Date tmpStart = new Date();
    Date tmpEnd = new Date();
    SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy hh:mm a");
    try {
    tmpStart = format.parse("01/10/2001");
    tmpEnd = format.parse("01/10/2002");
    } catch (Exception e) {
    System.out.println("Unable to parse the start and end date.");
    But I got an exception.

  • How to parse a string containing xml data

    Hi,
    Is it possible to parse a string containing xml data into a array list?
    my string contains xml data as <blood_group>
         <choice id ='1' value='A +ve'/>
         <choice id ='2' value='B +ve'/>
             <choice id ='3' value='O +ve'/>
    </blood_group>how can i get "value" into array list?

    There are lot of Java XML parsing API's available, e.g. JAXP, DOM4J, JXPath, etc.
    Of course you can also write it yourself. Look which methods the String API offers you, e.g. substring and *indexOf.                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to save a string input by the user to a file

    Hi,
    Can anyone please teach me how to save a string or several string that requires the input of the user into a text file?
    Your help is very much appreciated!
    Thank you!

    http://java.sun.com/docs/books/tutorial/essential/io/index.html

  • How can I have multiple inputs into the selector terminal of a case structure

    Hi everyone
    I have a question on how to wire multiple inputs in to the selector terminal of a case structure. 
    Currently, I have three switches, each switch determines different case. So if I switch the switch 1 is on, the numeric indicator will show 1. If the switch 2 is on, the numeric indicator will show 2, so on and so forth. However, the selector terminal will not allow me to wire multiply inputs into the case structure, I tried Bundle by Name, Bundle and Array to Cluster, but they did not work. I set the case structure with 3 cases, they are 1, 2 and 3.
    Could someone help me please. I have attach an image and the VI of the work I did so far.
    I have another question, is there a function which can toggle other switches to off when there is a switch has been toggled on.
    Thank you very much
    Tommy
    Attachments:
    Trial - Case Structure.vi ‏7 KB

    Tommy, attached find a cheeseball way of doing this that has given me a LOT of mileage over the years.  IT lends itself nicely to a couple of really good practices that NI recommend, but I have given you the bare-bones to "see under the hood".  
    The recommended practices:
    1. You can make this a nice tight sub-vi where you can put it into a core library of routines that you'll use over the years, even extending the logic to look only for changes, etc.
    2.  If you are thinking about Front Panel design considerations, you'll want to use arrays of controls where possible, as that's a nice neat way of containerizing your switch for both the FP and Block Diagram.
    Have fun.  I have TONS of these types of things, so feel free to PM me if you have any other needs.
    Wes
    Wes Ramm, Cyth UK
    CLD, CPLI
    Attachments:
    Boolean Switch Logic.vi ‏11 KB

  • How to convert a string value to date

    Dear All,
    I am new to powershell script, i was trying to store a Ad user password set date to a variable add, add a number of days to get the expire date.
    but when i try to convert the variable to date value, I am getting the error as below.
    Please help me......
    PS C:\script> $passwordSetDate = (get-aduser user1 -properties * | select PasswordLastSet)
    PS C:\script> $passwordSetDate
    PasswordLastSet
    7/15/2014 8:17:24 PM
    PS C:\script> $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)
    Cannot find an overload for "ParseExact" and the argument count: "3".
    At line:1 char:1
    + $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodException
        + FullyQualifiedErrorId : MethodCountCouldNotFindBest
    PS C:\script> $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)

    Dear All,
    I am new to powershell script, i was trying to store a Ad user password set date to a variable add, add a number of days to get the expire date.
    but when i try to convert the variable to date value, I am getting the error as below.
    Please help me......
    PS C:\script> $passwordSetDate = (get-aduser user1 -properties * | select PasswordLastSet)
    PS C:\script> $passwordSetDate
    PasswordLastSet
    7/15/2014 8:17:24 PM
    PS C:\script> $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)
    Cannot find an overload for "ParseExact" and the argument count: "3".
    At line:1 char:1
    + $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodException
        + FullyQualifiedErrorId : MethodCountCouldNotFindBest
    PS C:\script> $a = [datetime]::ParseExact($passwordSetDate,"MM/dd/yyyy HH:MM:SS", $null)
    In your post you ask how to convert a string value to a date.  The value returned from the Get-AdUser is already a date.  It does not need to be converted.
    Bill has sshown one way to convert a date to a string and there are other methods.  You need to clarify your question.
    If you are really trying ot convert strings to dates then you can start with this:
    [datetime]'01/21/1965 13:33:23'
    Most date strings aer autodetected by the class.
    ¯\_(ツ)_/¯

  • How to set a string input to accept only 1 and 0 (binary data)

    Hi
    I want to write a program that is supposed to take only binary data from the user. So I put a string control onto the front panel, wanting the user to be able to only type 1 or 0 in it. Is there a way to do that?
    Thanks

    Jean-Pierre Drolet wrote:
    Another slight flaw is that the string accepts Enter for a new line. It is easily fixed by setting it to "Limit to single line".
    True, it allows any non-ASCII through. Another solution would be to use some logical combination of VKey and Char, but it could get complicated. One of the simpler ways is the use of scancode and shift, as in the attached modification. Now ENTER, etc. is also discarded.
    I also agree that none of this seems appropriate to enter 4000 "0/1" characters on a fromt panel.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    BinaryStringControl_III.vi ‏24 KB

  • How to check particluar string in xml data

    Dear oracle Experts.
    Im using the following oracle database.
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production
    CORE 10.2.0.4.0 Production
    TNS for Linux: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production
    I have a following xml data..
    p_msg_in CLOB :=
    <DATA>
    <FLD FNR="ZZ0584" DTE="26SEP12" SRC="DXB" DES="DAC" />
    <AAA LBP="22334455" ETK="1234567/4" ACT="123" />
    <AAA LBP="223344" ETK="2345678/1" />
    <AAA LBP="223344" ETK="123456/1" ACT="345" />
    </DATA>
    then, im fetching header details like this..
    v_msg_xml := xmltype(p_msg_in);
    FOR i IN multicur(v_msg_xml, '/DATA/FLD') LOOP
    v_1:= i.xml.extract('//@FNR').getstringval();
    v_4:= to_date(i.xml.extract('//@DTE').getstringval(),'DDMONYY');
    v_5:= i.xml.extract('//@SRC').getstringval();
    v_6:= i.xml.extract('//@DES').getstringval();
    END LOOP;
    after this, I need to loop all the actual records one by one using this for loop. Here for each iteration , i need to check some string ( example ACT) is there or not. in the above example, records 1,3 have ACT value in it. So here i need to check some thing like this. if instr('<AAA LBP="223344" ETK="123456/1" ACT="345" />','ACT)>0 before I perform the below step.
    How to achieve this.
    I appreciate your help.
    thank you.
    FOR c IN multicur(v_msg_xml, '/DATA/AAA') LOOP
    v_7 := c.xml.extract('//@LBP').getstringval();
    v_8 := c.xml.extract('//@ETK').getstringval();

    SQL> DECLARE
      2 
      3    p_msg_in  clob := '<DATA>
      4  <FLD FNR="ZZ0584" DTE="26SEP12" SRC="DXB" DES="DAC" />
      5  <AAA LBP="22334455" ETK="1234567/4" ACT="123" />
      6  <AAA LBP="223344" ETK="2345678/1" />
      7  <AAA LBP="223344" ETK="123456/1" ACT="345" />
      8  </DATA>';
      9 
    10    v_msg_xml xmltype;
    11 
    12    v_1       varchar2(30);
    13    v_4       date;
    14    v_5       varchar2(30);
    15    v_6       varchar2(30);
    16    v_7       varchar2(30);
    17    v_8       varchar2(30);
    18 
    19  BEGIN
    20 
    21    v_msg_xml := xmltype(p_msg_in);
    22 
    23    select fnr, to_date(dte, 'DDMONRR'), src, des
    24    into v_1, v_4, v_5, v_6
    25    from xmltable('/DATA/FLD'
    26           passing v_msg_xml
    27           columns fnr  varchar2(30) path '@FNR'
    28                 , dte  varchar2(30) path '@DTE'
    29                 , src  varchar2(30) path '@SRC'
    30                 , des  varchar2(30) path '@DES'
    31         ) ;
    32 
    33     dbms_output.put_line('V1 = '||v_1);
    34     dbms_output.put_line('V4 = '||v_4);
    35     dbms_output.put_line('V5 = '||v_5);
    36     dbms_output.put_line('V6 = '||v_6);
    37 
    38     for r in (
    39       select lbp, etk
    40       from xmltable('/DATA/AAA[@ACT]'
    41              passing v_msg_xml
    42              columns lbp  varchar2(30) path '@LBP'
    43                    , etk  varchar2(30) path '@ETK'
    44            )
    45     )
    46     loop
    47       dbms_output.put_line('LBP = '||r.lbp||' ETK = '||r.etk);
    48     end loop;
    49 
    50  END;
    51  /
    V1 = ZZ0584
    V4 = 26/09/12
    V5 = DXB
    V6 = DAC
    LBP = 22334455 ETK = 1234567/4
    LBP = 223344 ETK = 123456/1
    PL/SQL procedure successfully completed

  • How can i request an input of data from a deployed web service via a html

    Hi all, I am currently having trouble with a web service. I want a client to be able to input a numerical value for a control in a deployed VI.
    At present i have one main vi that generates a signal and i've collected waveform data and displayed this data on a a chart. The web service uses a static folder containing html and javascript files. The html file calls the js file which parses the waveform data and returns to html to be stored as a chart_div. I have all the controls and indicators in one VI, connected by terminals using GET method.
    I am looking for a way of scripting a request form so that when called by the html file, the client user can input a control and change the values on the waveform graph. I also have an update button that requests updated data. 
    If anyone could suggest a method of how to accomplish this it would be SO helpful
    Thanks, Chris

    Hi Chris,
    I take it you are using the RESTful API method to GET the data. In that case you shoul be able to perform a http POST from your js code in order to update the controls.
    This could be done as form components are updated, or after a submit button is pressed (I'm sure you are familiar with this part).
    Please see here for more information: http://zone.ni.com/reference/en-XX/help/371361J-01​/lvhowto/build_web_service/
    I hope this helps.

  • How to decompose a string with ';' into Internal table

    Hello all,
    I need your help for find a Function module or Abap code.
    I have a file with the separator is the ';'
    Example of the contains of my file :
    521010;16;46048,00;;*Soucet*Odmena za
    524012;41;103807,00;;Zdrav.p.organizace
    524012;42;;18332,00;Zdrav.p.organizace
    I want a module function which can separate all the String separate by a ';' into a internal table :
    for example my internal table have 5 column :
    Num......|.....CC.....|............Credit....|...........Debit........|.....Label
    521010....|.....16.....|......46048,00.....|...........................|.....Soucet**Odmena za
    524012....|.....41.....|......103807,00...|...........................|.....Zdrav.p.organizace
    524012....|.....42.....|..........................|........18332,00....|.....Zdrav.p.organizace
    For read the date of my file is not a problem with ABAP Code :
    DO.
          CLEAR : ws_facm.
          break epetrini.
          READ DATASET myFile INTO test.
          IF sy-subrc EQ 0.
            IF ws_facm-codenreg = 'D'.
              APPEND ws_facm TO wt_facm.
            ENDIF.
          ELSE.
            EXIT.
          ENDIF.
        ENDDO.
    Thank you for your helps.
    Best regards Emilien
    Edited by: Emilien P. on Mar 31, 2010 4:30 PM
    Edited by: Emilien P. on Mar 31, 2010 4:34 PM
    Edited by: Emilien P. on Mar 31, 2010 4:35 PM
    Edited by: Emilien P. on Mar 31, 2010 4:36 PM

    Hi,
    Try whith this:
    DATA: str1 TYPE string,
          str2 TYPE string,
          str3 TYPE string,
          itab TYPE TABLE OF string,
          text TYPE string.
    text = `What a drag it is getting old`.
    SPLIT text AT space INTO: str1 str2 str3,
                              TABLE itab.
    Let me know if it works.
    Regards,
    Moh.

  • How can casting to String to InternetAddress

    Hello, I have to send and email and I'm using a InternetAddres to set the Address and the personal. I'm doing something like this:
    mensaje.setFrom(new InternetAddress(from.getAddress(),from.getPersonal()));The problem is that I receive this information in one String, I receive one of these options:
    Name <email>
    <email>
    Name Surname <email>
    How can I do to create a InternetAddress using that.
    InternetAddress from = new InternetAddress (email, Name);
    InternetAddress from = new InternetAddress (email, null);
    InternetAddress from = new InternetAddress (email, Name Surname);
    Javamail have any method to create that or I have to do a manual casting? Taking the String and dividing when I show a <>?
    Thanks!

    Your question is difficult to understand. Are trying to do the same thing as the poster of this other thread?
    http://forum.java.sun.com/thread.jspa?threadID=5153150&tstart=0
    In any case, you should NEVER do this:   sInitial = new String(sInitial.getBytes("UTF-8"), "UTF-8"); You can't change the encoding of a string, ever. In this case, the resulting string will be exactly the same as the original because both of the encodings are the same. If you use two different encodings, you'll probably end up with garbage.

  • How to convert a string to a Date obj ?

    Hi,
    String xx; "xx is from a table rs.getString();"
    Date dd = Date.valueOf(xx);
    id = today.compareTo(dd);
    Complier complains , why ?
    Thanks in advance.
    Philip

    Hi,
    I finally figured the reason. I have to put "java.sql.DatevalueOf( )" in the code. I guess there are 2 Date classes. One is in the Util.* and the other in sql.*...
    The one in Util.* means something else...
    Thanks anyway.
    Philip

  • How to analyze the String input??

    The program should accept integers but not the sentences for example
    the user enters "Hi how are you"
    the program should say"Sorry, please enter the integers"
    if the user enters "123454545"
    the program should work normally
    The main aim is to differentiate between sentences and integers

    You can use Exception handling to do this
    for example
       String userInput;
       int number;
       try
           number = Integer.parseInt(userInput);
       catch(NumberFormatException nex)
          System.err.println("please enter integer");
       }

Maybe you are looking for