Having problems parsing String to Date

Hello,
Could someone please explain to me why the following code snippet parses the day and year correctly but returns the month as January regardless of which date I supply?
SimpleDateFormat format = new SimpleDateFormat("M/D/y");
try { Date date = format.parse("5/5/2000"); }
catch (ParseException e) {}          
System.out.println(date.toString());
// returns --> Wed Jan 05 00:00:00 PST 2000

Refer to http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html
> SimpleDateFormat format = new SimpleDateFormat("M/D/y");Capital 'D' indicates Day in year. So day 5 in your example refers to the fifth day in Jan. Use small 'd', which indicates Day in month ...
Cheers

Similar Messages

  • Problem parsing the path data - error on jpgs

    Photoshop CS2 v9.0.2 Windows XP SP2
    Received the following error message in CS2: "Could not complete your request because of a problem parsing the path data"
    I began getting the message above after adding ITPC data to three .jpg files. The message appears when I try to open the files from either Bridge or Windows Explorer. Other files are not affected. The .psd master file with the same metadata opens ok. I tried clearing the ITPC data, but this had no affect. I also tried moving the file to a different folder and renamed the file with no success. The files open ok in Windows Paint and appear ok in Bridge.
    I created the ITPC data on one file in Photoshop and saved a metadata template. Then, in Bridge 1.0.4.6 I used the "replace metadata" command on the other two files.
    I searched the knowledge base and this forum. I found only one hit in the forum from 2007, but there were no responses.
    Can anyone describe what triggers this message, and how to avoid it or fix it?
    Thanks

    Foward / backward slashes should not cause issues, as they are part of the standard character set on any system for obvious reasons, but I would more assume that this is an issue in how Windows translates the file info to native paths and tries to access those paths for verification. I seem to recall having read something along those lines recently in relation to some security issues, but I'm not really sure. anyway, does "escaping" the characters improve the matter (\\ or \/)?
    Mylenium

  • HT1386 I am having problem syncing my itunes data from my computer to my ipod and ipad. My data is not fully transferred.  Can someone help me?

    I am having problems syncing my itunes data from my computer to my ipod and ipad.  The data from my computer is not transferring.  Can someone help me?

    What happens when you try to sync?
    Does any media sync?
    Was the iPod previous synced to another iTunes library/computer?
    Have you successfully synced from this iTunes library/computer before?
    Do the songs play in iTunes?
    Do you have the right boxes checked to sync?
    iTunes: Syncing media content to iOS devices and iPod        

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

  • Problem parsing the path data

    I am trying to open a PSD doc in Photoshop CS3 and I am getting an error: problem parsing the path data. Is there any way around this?

    Is the icon really an alias? Aliases have a hard-to-see arrow in the lower left corner. If you click once on the icon and do a Get Info, you'll be told if it's an alias, and if so, where the original is, or once was if the original is gone.
    Following Ramon and Buko's advice, I got rid of Norton products and several minor irritations at the same time.
    --Gene

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

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

  • Having problem while uploading the data.

    Hi All,
    i am facing some problem when trying to upload csv file in the database.
    ERROR:
    "SQL*Loader-704: Internal error: ulconnect: OCIServerAttach [0]
    ORA-12560: TNS:protocol adapter error".
    have anybody aware of this kind of problem or having knowledge regarding this problem.database is working fine.
    -rajnish

    Hi,
    About this error, you need to enable tracing and get the exact error from the listener trace files:
    12560, 00000, "TNS:protocol adapter error"
    // *Cause: A generic protocol adapter error occurred.
    // *Action: Check addresses used for proper protocol specification. Before
    // reporting this error, look at the error stack and check for lower level
    // transport errors.For further details, turn on tracing and reexecute the
    // operation. Turn off tracing when the operation is complete.Regards,
    Yoann.

  • Having problem with String ??

    It doesn't get into my if ...very strange
    String kol = "DOS";
    String val = attribut.getNodeValue();
    System.out.println(val); /*this show: DOS*/
    /* It doesn,t get into the if as se below the 2 string are the same*/
    if (kol == val)
    System.out.println("I m here");

    LOL I know how it feels. I did this I think on the very second day of my job. There was a ticket and I did this and was stuck for like an hour or so and then dared to ask a co worker find the problem.
    She came over to my desk and looked at the code for a few seconds and said, "I know you are new and are tense but I'll let you find out the issue."
    She sat on my chair witht hat look and I was on sitting on my desk booing myself when I saw that I was comparing two strings with == rather than with .equal LOL! !!!!!

  • Date string to Date object

    Hi
    How would i go about parsing some date strings in DD/MM/YYYY
    format into a date objects. I am sure its an easy problem but i
    cant find a simple way to do it as most of the API's want it a
    differnt format like MM/DD/YYYY
    Thanks for any help

    Hi,
    in the actionscript 3.0 cookbook there is a class DateFormat
    described, which allows to parse strings to date objects.
    You can download the code of the dateformat.as from here .
    http://www.rightactionscript.com/ascb/
    best regards,
    kcell

  • I'm having trouble with occasional high data consumption.  In November, I was told by Verizon I'd used 2 times my normal data.  Then again on Friday, Verizon told us we'd used approximatley 3 Giga Bytes on our Hot Spot.  Both of us had been working that d

    We're having problems with occasional mega data usage on our 3G Hot Spot.

    Power down your Jetpack while it is not in use, at least until you get your usage problem under control.  Bring your PC to a different area and see if you can let it sit connected for a while to complete whatever it is struggling with.

  • Having problems on removing old apps from App Store update is not working wright the change made my iPad go crazy

    Having problemes with new up date can't delete apps from iBook nor App Store everything change and it stink.

    You need to describe your problem and what is happening in a lot more detail than that, if you wish for help.
    Pete

  • Facing Problem in parsing a string to date

    Hi,
    I was trying to change a string into date with date format ("EEEE,MMM,d,h:mm") but I always get the year as 1970.
    here is my code
    String strDate="Saturday,Jan 19 7:31";
    String dateFormat3="EEEE,MMM,d,h:mm";
         try {
         DateFormat myDateFormat = new SimpleDateFormat(dateFormat3);
         result1=myDateFormat.parse(strDate);
    catch(ParseException pe) {
                System.out.println("ERROR: could not parse date in string \"" +
            }any solution for it.

    This is my actual code
    import java.text.DateFormat;
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.Locale;
    public class TestingDate {
          * @param args
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              String dateFormat="EEEE, MMM d h:mm a";
              Date test=new Date(2007,0,19, 19, 31);
              System.out.println(" original date is "+test);
              String stringResult=DateToString(test,dateFormat);
              System.out.println("Date to string is "+stringResult);
              Date dateResult=stringToDate(stringResult,dateFormat);
              System.out.println(" String to date is "+dateResult);
              String stringResult2=DateToString(dateResult,dateFormat);
              System.out.println(" Date to string  is "+stringResult2);
    public static String DateToString(Date test, String dateFormat) {
             String result = null;
             try {
                  DateFormat myDateFormat = new SimpleDateFormat(dateFormat);
                     result = myDateFormat.format(test);
                     //System.out.println(" reslut date is "+result);
              } catch (Exception e) {
                   System.out.println(" Exception is "+e);
              return result;
    public static Date stringToDate(String strDate,String dateFormat1){
         Date result1=null;
         try {
              DateFormat myDateFormat = new SimpleDateFormat(dateFormat1);
              result1=myDateFormat.parse(strDate);
         catch(Exception e){
              System.out.println(" exception is "+e);
         return result1;
    }I am facing problem in getting the actual date. Please suggest the solution.

Maybe you are looking for

  • Mid Year Go live - Taxable Income

    Dear Gurus,      Our SAP Payroll went live in the month of July. We have entered YTD data through INLK schema for April, May and June. I have entered 1) /401 Projection Factor, 2) /460 Income Tax, 3) /4ME Monthly Education cess, 4) /4MH Monthly Highe

  • Report generation write to file at interval

    Hi, I am using the report generation toolkit to write data to an excel sheet. I am recieving a lot of data but only want to save the data to the excel sheet every minute. I have found threads about doing this with the Write to Measurement Express VI

  • Import purchase order process

    hi all, wish you happy Christmas n early happy new year from my side.... i would like to know import po cycle... i am unable to find an detailed info related to this subject,so plz kindly help me out by sharing som

  • How do I safely get the side panels of the printer off

    How do I safely get the side panels off the printer. I am attempting a repair and do not want to break them

  • Can bluetooth 1.7 in my PowerBook G4 sync with IPhones bluetooth 2.0?

    I'm about to purchase an IPhone and does anyone know if I can sync my older PowerBook G4 with bluetooth ver. 1.7 with the Iphones ver. 2.0? Or would it be better to use a plugin antennae to go wireless with AT&T. If so....what are the specifics for t