Results 1 to 17 of 17
  1. #1
    jojo is offline Member
    Join Date
    Dec 2009
    Posts
    36
    Rep Power
    0

    Default [Solved] Why doesn't this time get parsed correctly?

    Hi guys for some reason this won't work:
    It works when i delete the Wed, and EEE, but i need that too..
    Anybody sees what i'm doing wrong because i can't seem to figure it out..?

    Java Code:
    	public static void main(String[] args)
    	{
    			try {    String str_date="Wed, 20 Apr 2011";
    		    DateFormat formatter = null ; 
    		Date date ; 
    		
    		     formatter = new SimpleDateFormat("EEE, dd MMM yyyy");
    		     formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
    		         date = (Date)formatter.parse(str_date);    
    		          System.out.println("Today is " +date );
    		} catch (ParseException e)
    		{System.out.println("Exception :"+e);  e.printStackTrace();  } 
    	}
    Last edited by jojo; 04-20-2011 at 03:37 PM. Reason: Solved

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,939
    Rep Power
    8

    Default

    What doesn't work about it?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    jojo is offline Member
    Join Date
    Dec 2009
    Posts
    36
    Rep Power
    0

    Default

    I get an error..

    java.text.ParseException: Unparseable date: "Wed, 20 Apr 2011"
    at java.text.DateFormat.parse(Unknown Source)
    at Test.main(Test.java:37)

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  5. #5
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,939
    Rep Power
    8

    Default

    It works for me too.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  6. #6
    jojo is offline Member
    Join Date
    Dec 2009
    Posts
    36
    Rep Power
    0

    Default

    Honstly, it should work.. but then why it doesn't work with me >.<
    this is kinda strange lol :S

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  8. #8
    jojo is offline Member
    Join Date
    Dec 2009
    Posts
    36
    Rep Power
    0

    Default

    I did, even created a new class etc, could this be a bug? I'm currently checking my java version, also from which location, timezone are you guys checking?
    edit: using JRE1.6 (JRE6) & jdk1.6.0_20
    Last edited by jojo; 04-20-2011 at 03:20 PM.

  9. #9
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,939
    Rep Power
    8

    Default

    I doubt it's a bug.

    I'm also using 1.6, and I'm in Washington, DC for what it's worth.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  10. #10
    jojo is offline Member
    Join Date
    Dec 2009
    Posts
    36
    Rep Power
    0

    Default

    Idk if it has something todo with location/timezone, but i'm from europe, belgium and it's strange it works with you but not when i try..

    once again my code.. but its the problem with the EEE part, because when i remove it, for some reason it works fine.. could it be language settings?

    Java Code:
    import java.text.DateFormat;
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    
    public class Test2 {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args)
    	{
    		try
    		{    
    			String str_date="Wed, 20 Apr 2011";
    			DateFormat formatter = null ; 
    			Date date ; 
    	
    			formatter = new SimpleDateFormat("EEE, dd MMM yyyy");
    			date = (Date)formatter.parse(str_date);    
    	        System.out.println("Today is " +date );		        
    		}
    		catch (ParseException e)
    		{
    			e.printStackTrace();  
    		} 
    	}
    
    }

  11. #11
    jojo is offline Member
    Join Date
    Dec 2009
    Posts
    36
    Rep Power
    0

    Default

    it are indeed my language settings... when i change it to Wo (Woensdag = wednesday) than it works.. xD .. so i must be able to set the language somewhere?

  12. #12
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,939
    Rep Power
    8

    Default

    Quote Originally Posted by jojo View Post
    could it be language settings?
    Maybe. What happens when you use "Wednesday" translated to the language you're using?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  13. #13
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,939
    Rep Power
    8

    Default

    I think you want to set the locale of SimpleDateFormat. Check out the API: SimpleDateFormat (Java Platform SE 6)
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  14. #14
    jojo is offline Member
    Join Date
    Dec 2009
    Posts
    36
    Rep Power
    0

    Default

    i tried
    formatter.setTimeZone(TimeZone.getTimeZone("GMT")) ;
    but that doesn't seem to work.. any ideas?

  15. #15
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,452
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by jojo View Post
    it are indeed my language settings... when i change it to Wo (Woensdag = wednesday) than it works.. xD .. so i must be able to set the language somewhere?
    Yep, time/date parsing/formatting depends on the time zone as well as the Locale. (there may be people speaking English in Belgium or people speaking Dutch/French in the USA).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  16. #16
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,939
    Rep Power
    8

    Default

    Quote Originally Posted by jojo View Post
    i tried

    but that doesn't seem to work.. any ideas?
    I wouldn't expect that to work. You're not trying to set your timezone (at least not for this bug), you should be setting the locale.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  17. #17
    jojo is offline Member
    Join Date
    Dec 2009
    Posts
    36
    Rep Power
    0

    Default

    i've placed this in constructor:
    Locale.setDefault(Locale.US);

    working fine now, thanks guys!!!

    Solved

Similar Threads

  1. Replies: 3
    Last Post: 08-23-2011, 12:46 PM
  2. I can't get this to run correctly
    By LostinJavaLand in forum New To Java
    Replies: 4
    Last Post: 07-15-2010, 06:49 AM
  3. Replies: 0
    Last Post: 06-16-2010, 07:35 AM
  4. calculate time diff for particular time period
    By baktha.thalapathy in forum New To Java
    Replies: 2
    Last Post: 05-24-2010, 04:10 PM
  5. Parsed Document
    By nick211001 in forum New To Java
    Replies: 1
    Last Post: 07-29-2007, 01:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •