Formatting a Date String in React Native

前端 未结 6 415
温柔的废话
温柔的废话 2020-12-29 01:05

I\'m trying to format a Date String in React Native.

Ex: 2016-01-04 10:34:23

Following is the code I\'m using.

var date = new Date(\"2016-01-         


        
6条回答
  •  悲哀的现实
    2020-12-29 02:06

    The Date constructor is very picky about what it allows. The string you pass in must be supported by Date.parse(), and if it is unsupported, it will return NaN. Different versions of JavaScript do support different formats, if those formats deviate from the official ISO documentation.

    See the examples here for what is supported: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse

提交回复
热议问题