Date issue in Firefox

后端 未结 4 1319
遥遥无期
遥遥无期 2021-01-06 09:06

I want to parse date in my page to Javascript\'s Date.

So I have this in my page

01-07-2012 01:04 PM

相关标签:
4条回答
  • 2021-01-06 09:16

    try this:

    var tagText = $(this).html();
    tagText = tagText.replace(/-/g, '/');
    var givenDate = new Date(tagText);
    alert(givenDate);
    
    0 讨论(0)
  • 2021-01-06 09:16

    What I must change to make it work with all major browsers?

    Write it in milliseconds.

    0 讨论(0)
  • 2021-01-06 09:24

    If you really want full cross-browser support for any date format, you should take a look at moment.js. It allows you to be explicit about the input format. For example:

    var m = moment('01-07-2012 01:04 PM', 'DD-MM-YYYY  hh:mm a');
    
    0 讨论(0)
  • 2021-01-06 09:28

    As explained in the documentation the string you are passing to the constructor of the Date object should be:

    String value representing a date. The string should be in a format recognized by the parse method (IETF-compliant RFC 1123 timestamps).

    Basically it should represent an RFC822 or ISO 8601 date.

    0 讨论(0)
提交回复
热议问题