Results 1 to 2 of 2
  1. #1
    frozseven is offline Member
    Join Date
    Jun 2014
    Posts
    1
    Rep Power
    0

    Angry date format changes on its own

    <script type="text/javascript">

    function CompareDates(id)
    {

    var monName = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec");

    var d = new Date(id);

    var curr_date = d.getDate();

    var curr_month = d.getMonth();

    var curr_year = d.getFullYear();

    return (curr_date + " " + monName[curr_month] + " " + curr_year);
    }

    </script>

    and then this calendar tag:

    <p:calendar

    id="testDate"

    styleClass="calendar"

    pattern="d MMM, yyyy"

    maxlength="10"

    onchange="$(this).val(CompareDates($(this).val())) "

    onfocus="$(this).mask('99/99/9999');"

    >

    <p:watermark for="testDate" value="mm/dd/yyyy" />

    </p:calendar>

    and for some unknown reason i don't know why the default date format that the textbox accepts is in 'mm/dd/yyyy'

    For example if i entered "13-05-2014" then it would return an error stating date is invalid.

    If i entered "12-05-2014" then it would return "5 Dec, 2014"

    I did not declare any dateformat anywhere except for the datepickers which as shown above, is 'd MMM, yyyy'

    Before this happened i trialed and error many different kind of codes to try to validate the date however it all didnt work and so i reverted it all back to the original codes.

    Last time the dateformat that the textbox accepted was 'dd/mm/yyyy' and it worked fine with my javascript function except the validation part.

    Now it still works except that the dateformat changed to 'mm/dd/yyyy'.

    I did try to use console.log to find out what's wrong but there were no error messages.

    could anyone help me and tell me what is going on here?

    Why has the dateformat changed by itself?

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,023
    Rep Power
    6

    Default Re: date format changes on its own

    This is a Java forum. I suggest you submit your question to a JavaScript forum.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. format date
    By JAVAWE in forum New To Java
    Replies: 4
    Last Post: 01-15-2014, 06:11 PM
  2. Date Format
    By riddhishah28 in forum AWT / Swing
    Replies: 1
    Last Post: 02-19-2011, 04:46 PM
  3. Format date
    By mine0926 in forum New To Java
    Replies: 11
    Last Post: 08-04-2010, 02:56 AM
  4. julian date to full date format
    By judy318 in forum New To Java
    Replies: 7
    Last Post: 11-02-2009, 01:17 PM
  5. Date Format
    By learnspring in forum New To Java
    Replies: 1
    Last Post: 11-16-2008, 06:16 PM

Posting Permissions

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