Turn your Mobile Apps into m-commerce apps – Learn More!

You're Browsing As A Guest! Register Now...
Become a Java Expert!

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



simple date format...y cant run? Rate Topic: -----

#1 yooxygen  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 20-January 08


Dream Kudos: 0

Share |

simple date format...y cant run?

Post icon  Posted 23 August 2008 - 09:33 PM

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 ;)
Was This Post Helpful? 0
  • +
  • -


#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • Icon

Reputation: 1434
  • View blog
  • Posts: 8,313
  • Joined: 18-April 07


Dream Kudos: 0

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

Re: simple date format...y cant run?

Posted 23 August 2008 - 10: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!" :snap:

This post has been edited by Martyr2: 23 August 2008 - 10:04 PM

Was This Post Helpful? 0
  • +
  • -

#3 yooxygen  Icon User is offline

  • New D.I.C Head
  • Pip

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 20-January 08


Dream Kudos: 0

Re: simple date format...y cant run?

Posted 24 August 2008 - 01:13 AM

View PostMartyr2, on 23 Aug, 2008 - 11:03 PM, said:

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!" :snap:



okok...^^ thx ya
Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users