JavaScript won't parse GMT Date/Time Format

后端 未结 6 2082
我在风中等你
我在风中等你 2021-01-22 06:33

I\'m trying to get JavaScript to parse a date and time format for me, with the eventual aim of telling me the days passed since that date and the time right now (locally).

6条回答
  •  广开言路
    2021-01-22 07:23

    The correct syntax should be:

        var thedate = "Oct 1, 2008 06:21:43";
        var inmillisecs = new Date(thedate);
    

    You have to take some steps to transform the String you're receiving into the format I showed. Using the american format also works

       var thedate = "10/1/2008 06:21:42";
       var inmillisecs = new Date(thedate);
    

提交回复
热议问题