Welcome to Dream.In.Code
Become a Java Expert!

Join 150,163 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,366 people online right now. Registration is fast and FREE... Join Now!




simple date format...y cant run?

 
Reply to this topicStart new topic

simple date format...y cant run?

yooxygen
23 Aug, 2008 - 09:33 PM
Post #1

New D.I.C Head
*

Joined: 20 Jan, 2008
Posts: 15


My Contributions
CODE

import java.util.*;
import javax.swing.*;
import java.text.*;

class Date
{
     public static void main (String[] args)
     {
         Date today;
        
         SimpleDateFormat simpleDF1,simpleDF2;
        
         today = new Date();
        
         simpleDF1 = new SimpleDateFormat( );
         simpleDF2 = new SimpleDateFormat("EEEE MMMM dd,yyyy");
        
         JOptionPane.showMessageDialog (null,"Today is "+simpleDF1.format(today));
        
         JOptionPane.showMessageDialog (null,"Today is "+simpleDF2.format(today));
        
        }
    }
        



y it say tat cannot format given Object as a date at java.text.DateFormat???

how to solve it?? thx wink2.gif
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Simple Date Format...y Cant Run?
23 Aug, 2008 - 10:03 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,660



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Be sure to include the import import java.util.Date; at the top of your file. You have to include this date object into your project because this form of the date class is what SimpleDateFormat expects. Once you do this you will get your program working just fine.

Edit: Also you want to change your class name from "Date" since there is already a Date class. Just so you don't run into potential problems later.

Enjoy!

"At DIC we be date importing code ninjas... we also import people, sausages, and mexican jumping beans... but all legally!" decap.gif

This post has been edited by Martyr2: 23 Aug, 2008 - 10:04 PM
User is offlineProfile CardPM
+Quote Post

yooxygen
RE: Simple Date Format...y Cant Run?
24 Aug, 2008 - 01:13 AM
Post #3

New D.I.C Head
*

Joined: 20 Jan, 2008
Posts: 15


My Contributions
QUOTE(Martyr2 @ 23 Aug, 2008 - 11:03 PM) *

Be sure to include the import import java.util.Date; at the top of your file. You have to include this date object into your project because this form of the date class is what SimpleDateFormat expects. Once you do this you will get your program working just fine.

Edit: Also you want to change your class name from "Date" since there is already a Date class. Just so you don't run into potential problems later.

Enjoy!

"At DIC we be date importing code ninjas... we also import people, sausages, and mexican jumping beans... but all legally!" decap.gif



okok...whatsthat.gif thx ya
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 02:50AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month