Problem with SimpleDateFormat.parse()

Hello
I have a problem with the parse-function in SimpleDateFormat.
When i try to parse the date Fri Jul 15 17:23:41 2005 with this pattern EEE MMM d HH:mm:ss yyyy i get the exception java.text.ParseException: Unparseable date: "Fri Jul 15 17:23:41 2005".
This is my code:
SimpleDateFormat df=new SimpleDateFormat("EEE MMM d HH:mm:ss yyyy");
try {
  df.parse(strDate);
} catch (ParseException e) {
  e.printStackTrace();
}Can someone explain me what i did wrong?
Thanks
Matthias

Since your name is "Matthias" it is possible that your locale is one that does not use the English language. If that is the case then your problem is that "Fri" or "Jul" are not correct abbreviations in your language.
Easiest way to test this idea is to format a date (such as now) using that SimpleDateFormat object and see what the output looks like.

Similar Messages

  • Strange problem with SimpleDateFormat.parse method

    I got something strange with this method.
    String pattern = "yyyy/MM/dd";
    String mydate = "2007/00/10";
    SimpleDateFormat formatter = new SimpleDateFormat(pattern);
    Date newdate = formatter.parse(mydate);
    I get "2006/12/10"
    is this correct.

    dongyisu wrote:
    and there no exception get thrown outYes it does. I ran this:
    import java.text.DateFormat;
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    public class DateFormatTest
       public static final String DEFAULT_DATE_FORMAT = "yyyy/MM/dd";
       public static void main(String[] args)
          DateFormat formatter = new SimpleDateFormat(DEFAULT_DATE_FORMAT);
          formatter.setLenient(false);
          for (int i = 0; i < args.length; ++i)
             try
                Date date = formatter.parse(args);
    System.out.println("input: " + args[i] + " date: " + date);
    catch (ParseException e)
    System.err.println(args[i] + " is not a valid date");
    and got this when I input "2007/00/10":
    com.intellij.rt.execution.application.AppMain DateFormatTest 2007/00/10
    2007/00/10 is not a valid date
    Process finished with exit code 0%

  • Problem with XML Parser For Java V2

    Get message:
    <Line 5, Column 40>: XSD-2021: (Error) Element not completed: 'doesNotWork'
    Parser Exception: Element not completed: 'doesNotWork'
    Element 'doesNotWork' is defined the same as 'works' except 'doesNotWork' uses a ref="" rather than defining element inline.
    This appears to be a bug in the parser.
    XML:
    <?xml version ="1.0"?>
    <example>
    <works anAttribute="something"/>
    <doesNotWork anAttribute="something"/>
    </example>
    Schema:
    <?xml version = "1.0" encoding = "UTF-8"?>
    <xsd:schema xmlns:xsd = "http://www.w3.org/2000/10/XMLSchema">
    <xsd:element name = "example">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="works">
    <xsd:complexType>
    <xsd:attribute name = "anAttribute" use = "required" type = "xsd:string"/>
    </xsd:complexType>
    </xsd:element>
    <xsd:element ref = "doesNotWork"/>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    <xsd:element name = "doesNotWork">
    <xsd:complexType>
    <xsd:attribute name = "anAttribute" use = "required" type = "xsd:string"/>
    </xsd:complexType>
    </xsd:element>
    </xsd:schema>

    Hi all,
    I am getting the same error. Is the schema parser being actively suppported. From replies to problems, it does not seem like it is. Also I am still having problems with 'required', ID attributes etc. Is there comprehensive documentation of what is and what is not supported.
    Any help appreciated
    Thanks
    Venu

  • Problem with C++ parser V2

    Hi,
    I encountered some problems with C++ XML Parser on NT (0acle 8.1.7).
    I can't use the function print on a Node
    => error LNK2001: unresolved external symbol "public: void __thiscall Node::print(unsigned char *,unsigned int,unsigned int,unsigned int)" (?print@Node@@QAEXPAEIII@Z)
    is this function exported ??
    I have not this problhme on Unix !
    (to work around on NT, i use the printBuffer function)
    Thanks,
    null

    Do you know when this future release will be available for NT, AIX and Compaq ?
    null

  • Problem with registering Parser - Recompiled source code, don't see any changes

    I had created a parser. I had register this parser with Ifs Manager. I had execute this following statement to see if been registered carefully:
    On user ifssys/ifssys
    sql)select name,stringvalue,bundle from odmv_property where name= 'p01';
    I see my parser....
    select name from odmv_propertybundle where id=1139;
    ParserLookupByFileExtension
    All it's ok. I upload a file with a 'p01' extension with option 'parser' on my Internet Explorer. All work fine.. My parser work. But I need to do some changes in my code. I update my code, recompile my code. My class file have been updated. After my parser (.class) file have been updated I upload a new file with parse option. I don't see any change I do in my code. Why??? How I can update my parser to view change. I have only recompile my code an place my new class files on the same directory. I have try again (change on code, recompile, test) and I don't see any changes.
    But I have test by change my classname. My classname before is Test1 and I have rename my classe by Test2. I have compiled this code and a file Test2.class have been generate. I have update my register parser with Ifs Manager to use the new classname Test2. I have chack with sql statement to see if my parser have been updated. I have been updated correctly. I have upload a new file with parse option and I see my change on my code..
    Do you have some explanations about that??
    How I can update my source code of a parser already registered to the parser take the change I do.
    Francois
    null

    Ok, but they have another manner to resolve this problem. If I upload a file with parser option on Windows Nt explorer (Using SmbServer or WcpServer). How I can update the class file into the JVM? I need the restart this those server or just one? If just one which server I need to restart?
    Thanks Francois
    null

  • Problem with SimpleDateFormat

    Hi all,
    I would like to parse a time (00:00:00) in String format into a Date obj. I am using the following code to achieve it. however, the result come out is not what i expect.
       String fromTimeStr = "00:00:00";
       TimeZone sg = TimeZone.getTimeZone("Asia/Singapore");
       System.out.println("Timezone "+sg);
       SimpleDateFormat DF = new SimpleDateFormat("HH:mm:ss");
       DF.setTimeZone(sg);
       Date time = DF.parse(fromTimeStr);
       System.out.println("DAte time"+ time);the output is as followed:
    Timezone sun.util.calendar.ZoneInfo[id="Asia/Singapore",offset=28800000,dstSavings=0,useDaylight=false,transitions=8,lastRule=null]
    DAte timeThu Jan 01 00:30:00 GMT+08:00 1970
    From what i know, the timezone of Singapore is fallen within the GMT+8 zone; thus the result should be Jan 01 00:00:00 GMT+08:00 1970
    My system timezone is "Kuala Lumpur\Singapore GMT+8".
    Could someone enlighten me what there is 30 minutes extra from the output.
    Thanks

    jnaish wrote:
    This is basically what I'm doing:
    package test;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    public class DateFormatError
         private SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
         private Date dateOfBirth;
         public static void main(String[] args)
              DateFormatError x = new DateFormatError();
              x.run();
         public void run()
              String dob = "10/06/1989";
              try
                   dateOfBirth = sdf.parse(dob);
              catch (Exception e)
              sdf.format(dateOfBirth);
              System.out.println(dateOfBirth.toString());
    }Edited by: jnaish on Feb 4, 2009 12:07 PMHey jnaish, thanks for the SSCCE, but your problem is probably already resolved after phdk's post. Just a small side note: never "swallow exceptions". Never ever! To "swallow an exception" is this:
    try {
      // something that may throw an exception
    } catch(AnException e) {
      // do nothing with it: ie, swallow it
    }because whenever something goes wrong, you will not notice it since nothing is even printed to the screen: this makes debugging your code very hard! Always at least print the stack trace:
    try {
      // something that may throw an exception
    } catch(AnException e) {
      e.printStackTrace();
    }so you will see some helpful message on your screen when something goes wrong.
    Good luck!

  • Problem with SAX parser - entity must finish with a semi-colon

    Hi,
    I'm pretty new to the complexities of using SAXParserFactory and its cousins of XMLReaderAdapter, HTMLBuilder, HTMLDocument, entity resolvers and the like, so wondered if perhaps someone could give me a hand with this problem.
    In a nutshell, my code is really nothing more than a glorified HTML parser - a web page editor, if you like. I read in an HTML file (only one that my software has created in the first place), parse it, then produce a Swing representation of the various tags I've parsed from the page and display this on a canvas. So, for instance, I would convert a simple <TABLE> of three rows and one column, via an HTMLTableElement, into a Swing JPanel containing three JLabels, suitably laid out.
    I then allow the user to amend the values of the various HTML attributes, and I then write the HTML representation back to the web page.
    It works reasonably well, albeit a bit heavy on resources. Here's a summary of the code for parsing an HTML file:
          htmlBuilder = new HTMLBuilder();
    parserFactory = SAXParserFactory.newInstance();
    parserFactory.setValidating(false);
    parserFactory.setNamespaceAware(true);
    FileInputStream fileInputStream = new FileInputStream(htmlFile);
    InputSource inputSource = new InputSource(fileInputStream);
    DoctypeChangerStream changer = new DoctypeChangerStream(inputSource.getByteStream());
    changer.setGenerator(
       new DoctypeGenerator()
          public Doctype generate(Doctype old)
             return new DoctypeImpl
             old.getRootElement(),
                              old.getPublicId(),
                              old.getSystemId(),
             old.getInternalSubset()
          resolver = new TSLLocalEntityResolver("-//W3C//DTD XHTML 1.0 Transitional//EN", "xhtml1-transitional.dtd");
          readerAdapter = new XMLReaderAdapter(parserFactory.newSAXParser().getXMLReader());
          readerAdapter.setDocumentHandler(htmlBuilder);
          readerAdapter.setEntityResolver(resolver);
          readerAdapter.parse(inputSource);
          htmlDocument = htmlBuilder.getHTMLDocument();
          htmlBody = (HTMLBodyElement)htmlDocument.getBody();
          traversal = (DocumentTraversal)htmlDocument;
          walker = traversal.createTreeWalker(htmlBody,NodeFilter.SHOW_ELEMENT, null, true);
          rootNode = new DefaultMutableTreeNode(new WidgetTreeRootNode(htmlFile));
          createNodes(walker); However, I'm having a problem parsing a piece of HTML for a streaming video widget. The key part of this HTML is as follows:
                <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
                  id="client"
            width="100%"
            height="100%"
                  codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
                  <param name="movie" value="client.swf?user=lkcl&stream=stream2&streamtype=live&server=rtmp://192.168.250.206/oflaDemo" />
             etc....You will see that the <param> tag in the HTML has a value attribute which is a URL plus three URL parameters - looks absolutely standard, and in fact works absolutely correctly in a browser. However, when my readerAdapter.parse() method gets to this point, it throws an exception saying that there should be a semi-colon after the entity 'stream'. I can see whats happening - basically the SAXParser thinks that the ampersand marks the start of a new entity. When it finds '&stream' it expects it to finish with a semi-colon (e.g. much like and other such HTML characters). The only way I can get the parser past this point is to encode all the relevant ampersands to %26 -- but then the web page stops working ! Aaargh....
    Can someone explain what my options are for getting around this problem ? Some property I can set on the parser ? A different DTD ? Not to use SAX at all ? Override the parser's exception handler ? A completely different approach ?!
    Could you provide a simple example to explain what you mean ?
    Thanks in anticipation !

    You probably don't have the ampersands in your "value" attribute escaped properly. It should look like this:
    value="client.swf?user=lkcl&stream=...{code}
    Most HTML processors (i.e. browsers) will overlook that omission, because almost nobody does it right when they are generating HTML by hand, but XML processors won't.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Problem with sax parser

    Hello..
    I have the following problem. When I parse an xml document with blank spaces and numbers with decimals, its sometimes comes out as one string and sometimes as two, for example "First A" sometimes comes out as "First" and "A" and sometimes as "First A", which is how its stored in the xml file. Same with numbers like 19.20. Im enclosing a little of my code..
    public void characters(char buf[], int offset, int len)
    throws SAXException
    if (textBuffer != null) {
    SaveString = ""+textBuffer;
    if(i>-1)
    numbers = SaveString;
    Whats wrong and how do I fix it.
    Best Regards Dan
    PS I have more code, in data and out data if needed.Ds

    Hello,
    I do not know if this is your problem, yet please find hereafter an excerpt of the SAX API:
    public void characters(char[] ch,
                           int start,
                           int length)
                    throws SAXException
    ... SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks;...
    ... Note that some parsers will report whitespace in element content using the ignorableWhitespace method rather than this one (validating parsers must do so)...
    In other words, I am afraid that your issue is the "standard behaviour" of a SAX parser.
    I hope it helps.

  • Problem with SAX parser with String format

    hi, all I have the next problem:
    I try to parse xml file with success, I write next code:
    ====================
    my_class saxUms = new my_class();
    File file = new File( "c:\\my_try_Response.xml" );
    InputSource src1 = new InputSource( new FileInputStream( file ) );
    XMLReader rdr = XMLReaderFactory.createXMLReader( "org.apache.xerces.parsers.SAXParser" );          rdr.setContentHandler( saxUms );
    rdr.parse(src1);
    ===================
    but when I try to parse the same in string variable, I write:
    ===================
    my_class saxUms = new my_class();
    StringReader strr = new StringReader(my_str);
    InputSource intt = new InputSource(strr);
    XMLReader prs= XMLReaderFactory.createXMLReader( "org.apache.xerces.parsers.SAXParser" );
    prs.setContentHandler(saxUms);
    prs.parse(intt);
    ===================
    and error occurs:
              "Exception: java.lang.ClassCastException: java.lang.StringBuffer"
    how to fix the problem?
    Thank you for collaboration!

    where does the exception stack trace say the error is occurring?

  • Problem with C++ parser V2 (XDK 9.0.1.2.0)

    Hi,
    The problem describe in a previous message (id=416237, march 2001) with the C++ XDK 8.1.7.1 still remains with the new XDK!
    I can't use the function print to a FILE* on a Node.
    I try to print to stdout or a file =>
    [Linstruction ` + 0x77F7CE4C ; emploie ladresse mimoire + 0x000000010 ;. La mimoire ne peut pas jtre + written ;.]
    No problem when I print to a buffer.
    To try it, i modified DOMSample.cpp :
    cout << "Dump the DOM" << endl;
    cout.flush();
    oratext xmlBuff[1024];
    //parser.getDocumentElement()->print(xmlBuff,1024,0,0); // it's ok
    parser.getDocumentElement()->print(); // don't work
    Thanks,

    This is a known issue and is being investigated. It only fails on Windows NT and the access violation occurs in the Windows NT stdio functions.

  • Problem with DateFormat.parse

    hi,
    I'm working using Java 1.5.
    i'm using SimpleDateFormat to parse date strings. My program has the following piece of code:
    Class DateConverter {
    SimpleDateFormat m_sdate = null ;
    public DateConverter() {
    this.m_sdate = new SimpleDateFormat("yyyyMMdd") ;
    public Date to_date(String dstr) {
    return this.m_sdate.parse(dstr) ;
    The date parsing works fine as long as I give dates upto "00010101" but throws java.text.ParseException for the value "00001231". I was just eager to know whether 00010101 is the least date that can be parsed???
    Thanks,
    Venkatesh

    I don't get a ParseException with your code; if there is an earliest date that can be parsed it's not 1/1/1.fmt = new SimpleDateFormat("yyyy/MM/dd");
    new SimpleDateFormat("dd.MM.y G").format(fmt.parse("0/12/31"));
    output: <31.12.01 BC>

  • SSXA: Problems with QueryText Parsing

    Hi.
    I have a strange issue with Site Studio For Extenal Application WebSite.
    I have a Element Definition that have a Query. Editing Data File and using this query directly in UCM works fine. However when i edit this Data File from wcm-contrib (directly in web) i'm getting a Query Text Parse error.
    From log file:
    services/6 05.21 15:43:38.176 IdcServer-6452035 !csSearchQueryParserParsingError,( xFCCContentTypes &lt;matches&gt; `5` &lt;AND&gt; xFCCContentTypesN2 &lt;matches&gt; `8` &lt;AND&gt; xWebsiteObjectType &lt;matches&gt; `Image` ),19 exception stack
    It's a encoding problem?. How can i solve it?.
    Thanks in advance.
    Regards.

    Hi,
    What is the full build version of UCM being used ?
    Thanks
    Srinath

  • New problems with simpledateformat

    sorry guys to my previous post i had solved the issue of formatting my date format..
    but i have a new problem now is that when i enter the 13 mnth 2006 simpledateformat auto helped me rectify to jan of 2007.. and i look through the simpledateformat class it does not have any methods to help me check the validity of the date i am inputting.. is there any other class i have to use to check the validity??

    hmm SimpleDateFormat doesn't have a set lenient
    method only calendar has that...Scroll down some more.

  • Problem with SimpleDateFormat (CommandLine vs WebApp)

    Hello Friends,
    I have a strange problem. Not sure what is the mistake from my side. I have simple class that returns formatted date based on TimeZone. It gives me different result if run on command line vs when used in web app. Below is the code & other information.
    import java.util.*;
    import java.text.*;
    public class Test {
         public static String getDateFormatted(String tZone) {
              DateFormat dfm = new SimpleDateFormat("dd-MMMM-yyyy HH:mm:ss z");
              dfm.setTimeZone(TimeZone.getTimeZone(tZone));
              return dfm.format(new Date());     
         public static void main(String ar[]) {
              System.out.println(getDateFormatted(ar[0]));
    Output From Command Prompt
    java Test PST
    06-October-2008 20:37:01 PDT
    Output From webapp running on Weblogic Server Version 10.0
    06-October-2008 23:37:04 GMT-04:00
    Java version from my command prompt
    java version "1.6.0_06"
    Java(TM) SE Runtime Environment (build 1.6.0_06-b02)
    Java HotSpot(TM) Client VM (build 10.0-b22, mixed mode, sharing)
    To confirm if this problem is due to JRockit that is used as default for Weblogic, I changed Java Home in setDomainEnv.cmd to Sun JDK. But still no luck.
    set BEA_JAVA_HOME=C:\bea\jrockit_150_11
    set SUN_JAVA_HOME=C:\bea\jdk150_11
    if "%JAVA_VENDOR%"=="BEA" (
         set JAVA_HOME=%SUN_JAVA_HOME%
    ) else (
         if "%JAVA_VENDOR%"=="Sun" (
              set JAVA_HOME=%SUN_JAVA_HOME%
         ) else (
              set JAVA_VENDOR=Sun
              set JAVA_HOME=C:\bea\jdk150_11
    Thanks & Appreciate any suggestions

    how are you getting the tZone in web application?
    are you taking it from the request?
    in that case the timezone will be according to the settings in the browser.

  • Problem with HTML Parser and multiple instances

    I have a parser program which queries a online shopping comparison web page and extracts the information needed. I am trying to run this program with different search terms which are created by entering a sentence, so each one is sent separately, however the outputs (text files) are the same for each word, despite the correct term and output file seeming passed. I suspect it might be that the connection is not being closed each time but am not sure why this is happening.
    If i create an identical copy of the program and run that after the first one it works but this is not an appropriate solution.
    Any help would be much appreciated. Here is some of my code, if more is required i will post.
    To run the program:
    StringTokenizer t = new StringTokenizer("red green yellow", " ");
            int c = 0;
            Parser1 p = new Parser1();
            while (t.hasMoreTokens()) {
                c++;
                String tok = t.nextToken();
                File tem = new File("C:/"+c+".txt");
                    p.mainprog(tok, tem);
                    p.mainprog(tok, tem)
                    p.mainprog(tok, tem);
    }The parser:
    import javax.swing.text.html.parser.*;
    import javax.swing.text.html.*;
    import javax.swing.text.*;
    import java.awt.*;
    import java.util.*;
    import javax.swing.*;
    import java.io.*;
    import java.net.*;
    public class Parser1 extends HTMLEditorKit.ParserCallback {
        variable declarations
       public void handleStartTag(HTML.Tag t, MutableAttributeSet a, int pos){
    ...methods
      public void handleText(char[] data, int pos){
           ...methods
      public void handleTitleTag(HTML.Tag t, char[] data){
      public void handleEmptyTag(HTML.Tag t, char[] data){       
      public void handleSimpleTag(HTML.Tag t, MutableAttributeSet a, int pos){
    ...methods
          static void mainprog(String term, File file) {   
    ...proxy and authentication methods
                        Authenticator.setDefault(new MyAuthenticator() );
                        HTMLEditorKit editorKit = new HTMLEditorKit();
                        HTMLDocument HTMLDoc;
                        Reader HTMLReader;
                      try {
                            String temp = new String(term);
                            String fullurl = new String(MainUrl+temp);
                            url = new URL(fullurl);
                            InputStream myInStream;
                            myInStream = url.openConnection().getInputStream();
                            HTMLReader = (new InputStreamReader(myInStream));
                            HTMLDoc = (HTMLDocument) editorKit.createDefaultDocument();
                            HTMLDoc.putProperty("IgnoreCharsetDirective", new Boolean(true));
                            ParserDelegator parser = new ParserDelegator();
                            HTMLEditorKit.ParserCallback callback = new Parser1();
                            parser.parse(HTMLReader, callback, true);
                            callback.flush();
                            HTMLReader.close();
                            myInStream.close();
                     catch (IOException IOE) {
                        IOE.printStackTrace();
                    catch (Exception e) {
                        e.printStackTrace();
          try {
                FileWriter writer = new FileWriter(file);
                BufferedWriter bw = new BufferedWriter(writer);
                for (int i = 0; i < vect.size(); i++){
                    bw.write((String)vect.elementAt(i));
                    if (vect.elementAt(i)!=vect.lastElement()){
                        bw.newLine();
                bw.flush();
                bw.close();
                writer.close();
            catch (IOException IOE) {
                        IOE.printStackTrace();
                    catch (Exception e) {
                        e.printStackTrace();
              }   catch (IOException IOE) {
                     System.out.println("User options not found.");
    }

    How many Directory Servers are you using?
    Are both serverconfig.xml files of PS instances the same?
    Set debug level to message in the appropriate AMConfig.properties of your portal instances and look into AM debug files.
    For some reason amSDK seems not to get the correct service values.
    -Bernhard

Maybe you are looking for

  • How can I list all the domains configured for Weblogic Servers?

    How can I list all the domains configured for Weblogic Servers? I saw a note, which says the following: "WebLogic Server does not support multi-domain interaction using either the Administration Console, the weblogic.Admin utility, or WebLogic Ant ta

  • My iPhone 6 is not showing in iTunes

    when starting iTunes my iPhone 6 not showing is not showing under devices

  • Backward Compatability solaris 10 to Solaris 9

    I am trying to mix executables compiled on Solaris 10 with C++ compiler 5.8 with shared libraries compiled on Solaris 9. On solaris 9 it says libm.so.2 file not found. what may be the solution to run the executable from solaris 10 to solaris 9

  • Why doesn't Wifi Sync work after updating ITUNE?

    Hello, I updated my Itune to 11.1.4.62 version. After updating, WIFI sync doesn't work anymore. I have to connect the cable to my laptop to sync it. Before this upgrade it was working fine. Now, I have Iphone 5. I run Windows 7. I did all the recomme

  • Manual Bank Reconciliation (ff67)

    Hi This is with reference to the manual bank reconciliation in ECC6.0 We have three geographical location and having 10 banks. We have defined each location as vendor and customer for transfer purpose. We use to transfer fund on regular basis from on