Results 1 to 6 of 6

Thread: SimpleDateFormat Exception problem

  1. #1
    Join Date
    Dec 2009
    Posts
    178

    SimpleDateFormat Exception problem

    Hello,
    I try to verify that an hour is a valid time, why I created a class that does the audit. But the code is giving me an error. So, if you would please help me sort out this problem it would be great. Here is the code
    Code:
    Public static boolean IsHeure(String tm, String frm)
    	{
    	      SimpleDateFormat s = new SimpleDateFormat(frm);
    s.setLenient(false);      
    	      try
    	      {
    	          s.parse(tm); / / returns one hours
    	          return true;
    	      }
    	      catch (Exception e)
    	      {
    	      	e.printStackTrace();
    	      	return false;
    	      } 
    	}

  2. #2
    Join Date
    Nov 2009
    Posts
    330

    Re: SimpleDateFormat Exception problem

    Hello,
    May be that your prescription are on 12 hours and not 24
    Code:
    ex 12 pm instead of 24
    use the following constructor with a local country time, you may try it
    Code:
    SimpleDateFormat (String pat, Locale loc)
    Constructs a SimpleDateFormat using the given pattern and the default date format symbols for the given local. Hope this will help you.

  3. #3
    Join Date
    Dec 2009
    Posts
    292

    Re: SimpleDateFormat Exception problem

    Hello,
    Even I had a similar type of a query. I thought my in my java code, even if I add.
    Code:
    sd.setDateFormatSymbols(new DateFormatSymbols(Local.country));
    An idea of how to force the java format to use French -> 24h instead of 12h with SimpleDateFormat. In any case my linux display the date is in 24 hours. Any help will be great for me. Thanks in advance.

  4. #4
    Join Date
    Nov 2009
    Posts
    356

    Re: SimpleDateFormat Exception problem

    Hello,
    I think in the class you Local method
    Code:
    getDefault ()
    whether the setting is good, so this is not the case using
    Code:
    setDefault (Local newLoc)
    Sets the default locale for this instance of the Java Virtual Machine. If you need any more information on this , then please do post back.

  5. #5
    Join Date
    Dec 2009
    Posts
    178

    Re: SimpleDateFormat Exception problem

    Hello,
    Here is what I refer the getLocal, en_US what seems good but as soon as I test more than one hours 1259 this does not occur despite the addition of:
    And here is the code:
    Code:
    SimpleDateFormat s = new SimpleDateFormat(format);
    s.setDateFormatSymbols(new DateFormatSymbols(Local.getDefault()));	
    }

  6. #6
    Join Date
    Nov 2009
    Posts
    347

    Re: SimpleDateFormat Exception problem

    Hey
    You can try the following code, see if it works with you.
    Code:
    public class Main {
    
    public static void main(String[] args)
    {
            tm_pr("Tue Mar 31 06:09:00 CEST 2009");
    }
    
    static Date sunms;
    static SimpleDateFormat tmdt = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy");
    
    public static void tm_pr(String time) {
        try {
          sunms=tmdt.parse(time);
          System.out.println(sunms);
        }
        catch (Exception e) {
          System.out.println(e.toString() + ", " + time);
        }
    
    }

Similar Threads

  1. Replies: 6
    Last Post: 12-07-2011, 11:14 AM
  2. Exception Handling in .Net
    By Bruno007 in forum Software Development
    Replies: 5
    Last Post: 25-12-2010, 01:30 AM
  3. Problem in handling exception with Regex
    By Gunner 1 in forum Software Development
    Replies: 5
    Last Post: 16-02-2010, 01:56 AM
  4. Getting exception in SQL
    By beelow in forum Software Development
    Replies: 3
    Last Post: 18-11-2009, 08:36 AM
  5. Unhandled exception
    By SeCTor 1 in forum Software Development
    Replies: 3
    Last Post: 25-10-2008, 03:02 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,710,819,547.69295 seconds with 16 queries