Reading simple date format

Hi,
I am attempting to use the simpledateformat in Java. I want it to read the inputted code, and store it, and then print it out again...
Here is what I have so far:
import java.util.*;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class Date     {
     //For date :
     static DateFormat df = new SimpleDateFormat("dd-mm-yyyy");
     public static void main(String[] args)
          //for date in form (dd-mm-yyyy)
          //reads input fromm keyboard
          Scanner data = new Scanner(System.in);
          //Asks for you to type in date.
          System.out.println("Useby date: (dd-mm-yyyy)");
          //Takes input as string value
          String input = data.next();
          Date useby = null;
          try
               useby = df.parse(input);
          catch (ParseException e)
               e.printStackTrace();
          //Prints useby date.
          System.out.println("Useby date: " + df.format(useby));
The line:
               useby = df.parse(input);
States that there is a type mismatch... "cannot convert from Date to Date"??? What does this mean???
I am unsure as to what all these lines mean as I got them off the net and was unsure about some of them...
If some1 could help it would be very much appreciated.
Thanks.

I think your code is getting confused between java.util.Date and your own class's name, which is Date. Rename your class, and you should be fine.
By the way, please use code tags when posting code. See CODE button above posting box. That will format your code such that it is much more readable.

Similar Messages

  • Regarding simple date format

    Hi,
    Can any one please tell what is simple date format for below format.
    2008-11-04T11:49:04.312-04.00

    Basil wrote:
    I think all are getting confused with my question, I dont want to know how to convert date
    to a a particular format, I want to know if there is any format for 2008-11-04T11:49:04.312-04.00
    like yyyy-MM-dd'T'HH:mm:ss.SSS for 2008-11-04T11:49:04.312. My JDK version is 1.4
    Edited by: Basil on Nov 4, 2008 7:43 AM
    Edited by: Basil on Nov 4, 2008 7:43 AMRead the link for SimpleDateFormat and make one. How is that hard to understand? And it is what you have been being told from the beginning, and would have realised had you actually read the API docs pointed to. All the information you need to do so is there.

  • Simple Date Format

    Hi,
    I have an entity object with some attributes, one of them is called "CREATED_ON", which i have specified as a history column (created on).
    I have specified a format type of Simple Date in my Control hint and a format of dd-MM-yyyy. I then created a view based on my entity and dragged the view as an adf creation form. I also dragged a commit button to commit my record.
    However, the date that is stored in my database have a non-zero time component (e.g. 10-JUL-2007 10:46:22). This is a problem becuase in my search form, the search criteria does not work (it requires the exact time also to work). I do not want to use TRUNC in my SQL query.
    Instead i want the date to be stored with the format mask that i have specified.
    Can you please help me?
    Thank you

    Do you really want to lose the time component altogether, or just make the query on date-without-time work?
    There would be no way of recovering the information about when during the day the row was created if you truncate the time information, but it's possible to achieve if that's what you want. Both are possible to achieve.
    To achieve the "losing the current time info forever" approach, add the following overridden method in your entity impl class that slightly changes the way the history attribute value is returned, in my case, for the HIREDATE attribute of an Emp example:
        protected Object getHistoryContextForAttribute(AttributeDefImpl attributeDefImpl) {
            Object ret = super.getHistoryContextForAttribute(attributeDefImpl);
            if (attributeDefImpl.getIndex() == HIREDATE) {
                ret = new Date(new java.sql.Date(((Date)ret).getValue().getTime()));
            return ret;
        }To achieve # 2 instead, just add a SQL-derived attribute to the view object with formula:
    TRUNC(HIREDATE)and then use that sql-derived attribute in the query form instead of the normal HIREDATE attribute.

  • Need to read Hex data format for Handheld device. (SAP AII RFID )

    Hello,
    we developed a custom screens for packing, unpacking, tag commission.. etc for handheld device for my client. the Serial number field  type is /ain/barcode. Its working fine. but for the new system need to read the Hex format. I created a new field in the screen. but the handheld device is not reading the Serial number in Hex format.
    Could anyone suggest me how to read Hex data in Handheld devices. We are using Motorola MC9090 Series.
    Regards,
    Kamal

    Hi
    Are you using the reader to read an RFID tag or for reading barcodes.
    Ideally, if you read an EPC Gen2 RFID tag, for example, the 96 bit encoded EPC is read and that can be converted to its equivalent  HEX format for posting the observation to SAP AII.
    In case of barcodes, the string is read as is printed on the barcode.

  • Simple date format update/cleansing not working

    Dear All,
    Some rows are not being updated after update
    create table X(
    Surname varchar2(20),
    dob varchar2(20),
    dobupdate varchar2(20));
    insert into X values('Hookman','22-Apr-78','22-Apr-78');
    insert into X values('Beverly','21/06/1966','21/06/1966');
    insert into X values('Wickham','01/23/1985','01/23/1985');
    insert into X values('Logmann','26/Dec/1972','26/Dec/1972');
    insert into X values('Scooby','30.04.1966','30.04.1966');
    insert into X values('Trumph','15-August-1967','15-August-1967');
    insert into X values('Delaware','Aug-03-1961','Aug-03-1961');
    insert into X values('Wicked','03.Sep.1961','03.Sep.1961');
    insert into X values('Orlando','18.September.1961','18.September.1961');
    SURNAME DOB DOBUPDATE
    Hookman 22-Apr-78 22-Apr-78
    Beverly 21/06/1966 21/06/1966
    Wickham 01/23/1985 01/23/1985
    Logmann 26/Dec/1972 26-DEC-1972
    Scooby 30.04.1966 30-APR-1966
    Trumph 15-August-1967 15-August-1967
    Delaware Aug-03-1961 03-AUG-1961
    Wicked 03.Sep.1961 03-SEP-1961
    Orlando 18.September.1961 18.September.1961
    9 rows selected.
    =====================================
    --Code below is meant to update person Beverly
    Update x set dobupdate = to_char(to_date(dobupdate,'DD/MM/YYYY'),'DD-MON-YYYY')
    where dobupdate like '__/__/____';
    error - not valid month
    =======================================================
    --Code below is meant to update person  Trumph
    Update x set dobupdate = to_char(to_date(dobupdate,'DD-MONTH-YYYY'),'DD-MON-YYYY')
    where dobupdate like '__-_____-____';
    0 row/s updated
    =========================================================
    --Code below is meant to update person Orlando
    Update x set dobupdate = to_char(to_date(dobupdate,'DD.MMMM.YYYY'),'DD-MON-YYYY')
    where dobupdate like '__._____.____';
    0 row/s updated
    Where am I going wrong. I hvae no problems with updating other records in the table except fot just these three patterns.
    Help please.
    Cube60

    Thanks Warren, both suggested codes did not work and I can see why now. Alex has pointed it out.
    Alex brought me to realise Wickham's DOB is in the American format. The update query could not resolve that format and how to update it but at least it could have updated that of Beverly and left that of Wickham.
    After deleting Wickham completely, the update query worked on Beverly.
    Am just doing some data cleansing from a poorly designed Access database now meant for Oracle.
    So nothing can be done to resolve such mixture of date formats, I mean Uk and American.
    But now, Why are the update statement below coming with 0 records updated.
    The dates to be update are written like this 15-August-1967 and 18.September.1961 respectively
    --Code below is meant to update person Trump
    Update x set dobupdate = to_char(to_date(dobupdate,'DD-MM-YYYY'),'DD-MON-YYYY')
    where dobupdate like '__-__-____';
    0 row/s updated
    =========================================================
    --Code below is meant to update person Orlando
    Update x set dobupdate = to_char(to_date(dobupdate,'DD.MMMM.YYYY'),'DD-MON-YYYY')
    where dobupdate like '__._____.____';
    0 row/s updated
    many thanks
    cube60
    Message was edited by:
    cube60

  • Help :  Simple Date Formats Problem in JDev11 [TP4] ?

    Hi ;
    I use ADF/JSF in JDeveloper 11 [TP4].
    in JSF Page
    what can I do to enter Date format mask dd-mm-yyyy hh:mi:ss
    to Return my Date Format mask like
    mi-mm-yyyy meaning minute-month-year
    in another column ?
    and I know The format mask is defined in a File called formatinfo.xml .
    Thanks & Regards
    Forakora

    Hi,
    if it is for display then you don't need to change it in the model but can link the output text component to a managed bean that gets the stored date value to then change it to the format you prefer. This however may not be suitable if the date should be updated from that column

  • Simple date format with 1st 2nd 3rd etc

    hai
    i want to dispaly the date in the format
    25th of December 2004
    i tryed to format in SimpleDateFormat, but there is not special format to display date as 1st 2nd 3rd.
    can anybody help me how to do this
    Archi

    THANKS YOU
    THANKS FOR YOUR VALUABLE RESPONSE
    THAT I KNOW VERY VERY WELL HOW TO DO THAT.
    ITS URGENT I DONT WANT TO WASTE TO "INVENT A NEW STUFF"
    ARCHI.

  • Does Simple Date Format suppourts This convrsion??

    Hi ,
    I am getting this Date as String
    String str = "Fri May 13 2011 19:59:09 GMT 0530 (India Standard Time)";
    How to convert this Date Object into yyyy-mm-dd HH24:Mi:ss Format ??
    I have not seen any example using SimpleDateFormat with this format ??
    Please can anybody please show me how to do this ??

    user10503747 wrote:
    Hi ,
    I am getting this Date as String
    String str = "Fri May 13 2011 19:59:09 GMT 0530 (India Standard Time)";
    How to convert this Date Object into yyyy-mm-dd HH24:Mi:ss Format ??
    I have not seen any example using SimpleDateFormat with this format ??
    Please can anybody please show me how to do this ??The following works for me.
    String str = "Fri May 13 2011 19:59:09 GMT 0530 (India Standard Time)";
    str = str.replace("GMT ", "GMT +");
    SimpleDateFormat sf = new SimpleDateFormat("EEE MMMMMMMMMMM d yyyy H:m:s 'GMT' Z");Although not relevant to your actual problem the above will not work if '-' is used instead of the '+'. No idea why that is. It parses but seems to ignore the offset in that case.

  • Simple Date Format problem

    I am having trouble with the following code. It works fine on one computer but not on another.
    Calendar cal = Calendar.getInstance(TimeZone.getDefault());
    Date date22 = cal.getTime();
    System.out.println(date22);
    String details = sdf.format(date22);
    System.out.println(details);
    StringTokenizer str = new StringTokenizer(details, "-", false);
    The working ones output is:
    Thu Jul 14 12:06:33 GMT 2005
    14-07-2005-12-06-33
    However on the computer where it doesn't work, I get this:
    Fri Aug 05 13:13:59 BST 2005
    Exception in thread "Thread-0" java.lang.NullPointerException
    Which point to line: String details = sdf.format(date22);
    From what I can see, the only difference is BST instead of GMT, but I can't seem to change this.
    It is running under Windows.
    Any help will be MUCH appreciated, as I am stumped!
    Thanks. :)

    The difference is that in the latter sdf is never assigned a non-null value. Since you didn't post the code that initializes sdf, we've got no way of knowing what went wrong.

  • Regarding java.util.date / simple date format

    Hi Friends,
    I have a weired requirement where I am suppose to get time in millisecond for 3 scenarios.
    1. next 07:00 time
    2. next monday 07:00
    3. on next 1st 07:00
    Swing provides some jar where I can get next day - but not sure if I can play around to get my data.
    need your inputs.
    appreciate your quick reply friends,
    Chintan
    P.S. the reason I have to do so is
    1. I have 3 kind of reports - few reports expire daily - few weekly - few monthly.
    2. I am going to fetch the report from the external system and store (cache) in my db.
    3. Administrator can configure that when exactly the report is going to be updated in external system.
    4. So lets say for daily - every day at 7 it will be updated - so when I read the cached data, I want to compare the stored time stamp with next 7:00 time stamp and if my stored timestamp is less than next 7:00 time stamp - i can use the cached data and similarly for weekly and monthly.
    Please let me know if you have more questions.

    I'll just add an example.
    say I added a report to DB at 1188563489217 and my
    cutoff is weekly that is on next monday at 7:00 in
    the morning - at that time my milliseconds would be
    1188783033888
    now as far as my stored milliseconds are less than
    1188783033888 i can read it from my db and if my
    stored milliseconds are greater than 1188783033888
    then I need to refetch the report.
    Now for this task - every time i make a call to my DB
    - i have to get time in milli seconds for next monday
    7:00.
    Is it possible??
    I am badly struck over here - please guide.
    Chintan
    Appreciate your help buddies.
    ChintanTake the hint if the date string is 35:11:2007 07:00 in dd:MM:yyyy HH:mm format then the parsed date will be 05:12:2007 07:00.
    your problem is actually a piece of cake ;-)

  • Format date with simple date format

    Hello
    I want to parse String to date. My method is
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    Then
    Date date = dateFormat.parse("2007-17-1100 11:11");
    It can be seen that the String "2007-17-1100" is invalid date. However, I donot know why it still can be parsed. Result is "Thu May 05 11:11:00 NZST 2011"
    Could you please explain. I want this one cannot be parsed.
    Many thanks
    shoa

    SimpleDateFormat dateFormat = new
    SimpleDateFormat("yyyy-MM-dd HH:mm");
    Then
    Date date = dateFormat.parse("2007-17-110011:11");
    >
    IIn my knowledge there is only 12 months in a Year.There are. But as long as the parsing is 'lenient' it knows how to handle month numbers greater than 12.
    @OP: Check out the setLenient() method. A setLenient(false) should make it work the way you want.

  • Simple date format probem

    i wrote a method to convert a String to Calendar, but i have an error.
    The calendar object generated always has the month set to january and i don´t know why.
    This is my code
         static SimpleDateFormat df=new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
                          public static Calendar dateString2Calendar(String s) throws ParseException {
              Calendar cal=Calendar.getInstance();
              Date d1=df.parse(s);
              cal.setTime(d1);
              return cal;
         }  if the source String is: 2008-09-04 17:54:09 my Calendar gets the value: Fri Jan 04 17:54:09 CET 2008
    Where is my mystake?
    Regards

    upps i am feeling very very stupid....
    anyway thanks BigDaddyLoveHandles !!!!!!!

  • Simple Date Formatting

    I am a newbie to Java and was wondering if anyone knew of a easy way to format and date without having to write a whole function to format a date??

    I need more information what you are trying to do?
    Do you want to convert a string to a date are a date in one format to other.
    I suggest you to go through the following class API
    SimpleDateFormat
    Hope this will help you get some info about formatting
    Happy Coding
    Sampath

  • Editable and Read-Only Date Picker have different display formats -- Bug?

    Hi all,
    This is a follow on to a previous posting about getting a Date Picker field to display read-only (Date Picker and Read-Only Condition works on LAST state of element
    Now past that hurdle, I have noticed something about the date picker field when it is displays read-only. Namely, the date format is not the format selected, nor does the read-only date format comply with the format mask in the source section.
    I've modified my small test app to work as intended in order to demonstrate this feature. I also opened it up so everyone can see it <blush>. You can find it here: http://htmldb.oracle.com/pls/otn/f?p=42513: Please navigate to the Update Project tab.
    When a project in Program One through Four is selected (which has a Spec Committed date), the date is displayed DD-MON-YY format. When a project the other Programs (which do not have Spec Committed dates at the time of this writing) are selected, and a date value selected with the date picker, the date is displayed in the anticipated DD-MON-YYYY format.
    Anyone else notice this, or have I just missed something obvious?
    Thanks,
    Petie

    I'm not sure why this happens but to work around it I added this before header process code to the page:
    execute immediate 'alter session set nls_date_format = ''DD-MON-YYYY''';
    Scott

  • Problem with  date format "dd-MM-yyyy"

    hi all,
    i am using jdev 10.1.3.2
    My application ADF Swing app.
    in my database i have a table employee which contains "birthday".
    my problem is that i must use date format"dd-MM-yyyy".
    i added this format into "formatinfo.xml" file.
    than i choose it in my EO.
    i create a form which contains employees.
    for example i have an employee with a birthday=25-10-1970
    in my text field if user puts "1970-10-25"'which is not the best format) he will have a correct result "25-10-1970"
    but if user puts "25-10-1970" he will have as result "21-02-0031" which is not the real value.
    please help me.
    thanks.
    PS: i did some research before posting but i didn't find yet

    Rouz,
    Did you try what i said before?
    * Open you EntityObject
    * Expand the attribute tree
    * Choose your DOB attribute
    * Choose the Control hints pane on the right
    * Choose Formater: Simple date format
    * Choose Format mask dd-MM-yyyy
    Run your application and try it.
    This is how i change the format and it works perfectly.
    I uses the correct format to show the date and it enables me to edit the date using the format mask dd-MM-yyyy
    Edit: I just tried it myself. I can only reproduce it by removing my mask. Ergo, the application expects the default american format yyyy-MM-dd. By entering a date in the format dd-MM-yyyy the framework will convert it to yyyy-MM-dd and you'll end up with 0031-02-21.
    CONCLUSION follow the steps i discribed above to set your mask and you'll be fine.
    Message was edited by:
    Smolders Johan

Maybe you are looking for

  • Print BI Publisher Report from SIM

    Hi. Can I set some parameters in the report link .xdo in SIM for print a report? I want to print a report in XSL-XML (from XSL template) format by default!! (and NOT in XML Data BI Publisher). Like: /folder/name_report/name_report.xdo?_xt=XMLDIRECT&_

  • IPhoto faces gone since upgrade to 9.6.1

    Hi, Something strange is happening here. Since I upgraded iPhoto to 9.6.1, the Faces feature doesn't work anymore. When I click Faces in the left sidebar (which shows all faces' names and a thumbnail), well, all the names appear but with a black squa

  • How to add ASm diskgroup in ASM oracle 10.1.0.4.0

    Hi experts, We are using IBM AIX 5.3L OS on IBM Servers. Oracle Database EE 10G 10.1.0.4.0, RAC and ASM Presently There are 3 diskgroup (Filesystem) in my DB suppose +ABC +DEF +GHI Now I want to add a new Diskgroup (File system) Say +XYZ and I want t

  • Zen Vision M (60GB) and supported devices (USB Host Featu

    I would know if Canon Powershot A520 is a supported device by USB Host Feature. thanks mat

  • HP7510 REPLACING CARTRIDGE DURING PRINTING

    When doing a large print job, a print cartridge runs out. However if you lift the lid to stop the printing and replace the cartridge, the cartridge carrier goes to the right and the cartridge cannot be changed. The only way of getting the carrier in