SimpleDateFormat

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • oll3i
    Contributor
    • Mar 2007
    • 679

    #1

    SimpleDateFormat

    Date date = new Date();
    SimpleDateForma t formatter = new SimpleDateForma t("dd-MM-yyyy HH.mm.ss");
    String date_formated = formatter.forma t(date);

    why eclipse highlights new Date();
    as an error
    i imported what's needed
  • oll3i
    Contributor
    • Mar 2007
    • 679

    #2
    after compilation i get this when i call the function write_to_file which has new Date()
    Exception in thread "AWT-EventQueue-0" java.lang.Error : Unresolved compilation problem:
    The constructor Date() is undefined

    at zad11.Konto.wri te_to_file(Kont o.java)
    at zad11.Konto.dep ozyt(Konto.java )
    at zad11.Konto.acc ess$2(Konto.jav a)
    at zad11.Konto$2.a ctionPerformed( Konto.java)
    at javax.swing.Abs tractButton.fir eActionPerforme d(Unknown Source)
    at javax.swing.Abs tractButton$Han dler.actionPerf ormed(Unknown Source)
    at javax.swing.Def aultButtonModel .fireActionPerf ormed(Unknown Source)
    at javax.swing.Def aultButtonModel .setPressed(Unk nown Source)
    at javax.swing.pla f.basic.BasicBu ttonListener.mo useReleased(Unk nown Source)
    at java.awt.Compon ent.processMous eEvent(Unknown Source)
    at javax.swing.JCo mponent.process MouseEvent(Unkn own Source)
    at java.awt.Compon ent.processEven t(Unknown Source)
    at java.awt.Contai ner.processEven t(Unknown Source)
    at java.awt.Compon ent.dispatchEve ntImpl(Unknown Source)
    at java.awt.Contai ner.dispatchEve ntImpl(Unknown Source)
    at java.awt.Compon ent.dispatchEve nt(Unknown Source)
    at java.awt.Lightw eightDispatcher .retargetMouseE vent(Unknown Source)
    at java.awt.Lightw eightDispatcher .processMouseEv ent(Unknown Source)
    at java.awt.Lightw eightDispatcher .dispatchEvent( Unknown Source)
    at java.awt.Contai ner.dispatchEve ntImpl(Unknown Source)
    at java.awt.Window .dispatchEventI mpl(Unknown Source)
    at java.awt.Compon ent.dispatchEve nt(Unknown Source)
    at java.awt.EventQ ueue.dispatchEv ent(Unknown Source)
    at java.awt.EventD ispatchThread.p umpOneEventForF ilters(Unknown Source)
    at java.awt.EventD ispatchThread.p umpEventsForFil ter(Unknown Source)
    at java.awt.EventD ispatchThread.p umpEventsForHie rarchy(Unknown Source)
    at java.awt.EventD ispatchThread.p umpEvents(Unkno wn Source)
    at java.awt.EventD ispatchThread.p umpEvents(Unkno wn Source)
    at java.awt.EventD ispatchThread.r un(Unknown Source)

    Comment

    • DeMan
      Top Contributor
      • Nov 2006
      • 1799

      #3
      There are two different Date() classes in java.util.Date and java.sql.Date
      The java.sql.Date does not have a constructor with no arguments Date(), you may want to be sure that your program is useing the correct one.....

      You may also like to look up the Calendar class in the java API, as (Depending on what you need to do) it may be mroe useful

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by oll3i
        Date date = new Date();
        SimpleDateForma t formatter = new SimpleDateForma t("dd-MM-yyyy HH.mm.ss");
        String date_formated = formatter.forma t(date);

        why eclipse highlights new Date();
        as an error
        i imported what's needed
        Use GregorianCalend ar for dates.

        Comment

        Working...