score:0

Can't you just cut of the last 6 chars of that string? You might then round the miliseconds and eventually add a second to you time object.

score:0

This is simpler and in one line:

new Date('01/09/2015 06:16:14.123'.split(".")[0])

score:2

Many ways to Rome. The given code will return '(datestr=) 2011-4-4 19:27:39.92'. Is that what you look for?

var darr = '2011-04-04 19:27:39.92034'.split('.')
  , dat=new Date(darr[0])
  , datestr = '';
dat.setMilliseconds(Math.round(darr[1]/1000));
datestr = [ [dat.getFullYear(),dat.getMonth()+1,dat.getDate()].join('-')
            ,' ', 
            [dat.getHours(),dat.getMinutes(),dat.getSeconds()].join(':')
            ,'.',
            dat.getMilliseconds()
          ].join('');

score:9

JS built in Date class should be able to handle this, and getTime() can return milliseconds since start 1970 (UNIX time). Watch out for time zone issues though; the constructor may interpret the date/time as being local, but getTime()'s milliseconds since 1970 may be in UTC, baking in a conversion that is difficult to remove.

new Date("2011-04-04 19:27:39.92034").getTime()
1301941659920

Related Query

More Query from same tag