Parse DateTime string in JavaScript

前端 未结 9 2183
别跟我提以往
别跟我提以往 2020-11-22 12:15

Does anyone know how to parse date string in required format dd.mm.yyyy?

相关标签:
9条回答
  • 2020-11-22 13:05

    Use Date object:

    var time = Date.parse('02.02.1999');
    document.writeln(time);
    

    Give: 917902800000

    0 讨论(0)
  • 2020-11-22 13:10

    refs: http://momentjs.com/docs/#/parsing/string/

    If you use moment.js, you can use "string" + "format" mode

    moment(String, String);
    moment(String, String, String);
    moment(String, String, Boolean);
    moment(String, String, String, Boolean);
    

    ex:

    moment("12-25-1995", "MM-DD-YYYY");
    
    0 讨论(0)
  • 2020-11-22 13:11

    I'v been used following code in IE. (IE8 compatible)

    var dString = "2013.2.4";
    var myDate = new Date( dString.replace(/(\d+)\.(\d+)\.(\d+)/,"$2/$3/$1") );
    alert( "my date:"+ myDate );
    
    0 讨论(0)
提交回复
热议问题