CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Hybrid View

  1. #1
    Join Date
    Aug 2012
    Posts
    2

    new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2009-03-08 02:38:13")

    returns: Sun Mar 08 03:38:13 PDT 2009. Actually, if I change the date&time to "2009-03-08 03:38:13", it returns the same thing!

    Here is the code:

    public static void main(String[] args) {
    SimpleDateFormat dateFormat =
    new SimpleDateFormat(DATE_TIME_FORMAT);
    //dateFormat.setLenient(
    false);
    try
    {
    System.
    out.println("date is "+dateFormat.parse("2009-03-08 03:38:13"));
    System.
    out.println("date is "+dateFormat.parse("2009-03-08 02:38:13"));
    }
    catch (ParseException e) { e.printStackTrace(); }
    }

    If dateFormat.setLenient(false) is uncommented out, it throws a ParseException.

    What a weird problem. Does anybody have any ideas?


  2. #2
    Join Date
    Aug 2012
    Posts
    2

    Re: new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2009-03-08 02:38:13")

    Sorry, DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";

  3. #3
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2009-03-08 02:38:13")

    It works perfectly on my system. I get the correct date and times and lenient does not throw an exception.

    Are you sure this is the code you are running?
    What OS are you running on and what version of Java are you using?
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured