Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. date_time problum in java??

date_time problum in java??

Scheduled Pinned Locked Moved Java
questionjavalearning
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AmbiguousName
    wrote on last edited by
    #1

    hello guys....This is exactly the same code im copying from a book but yet it producing an exception saying "Can not format given object as Date"...while the author has shown the input in book...

    import java.text.*;
    import java.util.*;

    class Date {
    public static void main(String [] args) {
    Date date = new Date();
    SimpleDateFormat sdf;

    	//will show time
    	sdf = new SimpleDateFormat("hh:mm:ss");
    	//System.out.println(sdf.format(date));
    
    	//will show day + date + time
    	sdf = new SimpleDateFormat("dd MMM yyyy hh:mm:ss");
    	System.out.println(sdf.format(date));
    	
    	//will show day + date
    	sdf = new SimpleDateFormat("E MMM dd yyyy");
    	System.out.println(sdf.format(date));
    }
    

    }

    what is wrong with this code

    O 1 Reply Last reply
    0
    • A AmbiguousName

      hello guys....This is exactly the same code im copying from a book but yet it producing an exception saying "Can not format given object as Date"...while the author has shown the input in book...

      import java.text.*;
      import java.util.*;

      class Date {
      public static void main(String [] args) {
      Date date = new Date();
      SimpleDateFormat sdf;

      	//will show time
      	sdf = new SimpleDateFormat("hh:mm:ss");
      	//System.out.println(sdf.format(date));
      
      	//will show day + date + time
      	sdf = new SimpleDateFormat("dd MMM yyyy hh:mm:ss");
      	System.out.println(sdf.format(date));
      	
      	//will show day + date
      	sdf = new SimpleDateFormat("E MMM dd yyyy");
      	System.out.println(sdf.format(date));
      }
      

      }

      what is wrong with this code

      O Offline
      O Offline
      O Phil
      wrote on last edited by
      #2

      I would say : you shouldn't name the class as Date, since it can be confusing with the Date valuetype.

      ...

      class DateTest {

      ...

      }

      A 1 Reply Last reply
      0
      • O O Phil

        I would say : you shouldn't name the class as Date, since it can be confusing with the Date valuetype.

        ...

        class DateTest {

        ...

        }

        A Offline
        A Offline
        AmbiguousName
        wrote on last edited by
        #3

        thanx.... :)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups