-1

I have a var in js which is represented like so: "lastTimeModified": "2019-02-26T11:38:20.222Z"

and I want to add to it 1ms

I have tried something like this:

dateObj = new Date();
dateObj.setMilliseconds(1);
var newDate = lastTimeModified + dateObj

but that doesn't seem to work.

2 Answers2

3

If you can get your date in milliseconds than you can directly add 1 millisecond to it

var date = new Date(lastTimeModified)    // convert string to date object
var mill = date.getMilliseconds()        // Get millisecond value from date
mill += 1                                // Add your one millisecond to it
date.setMilliseconds(mill)               // convert millisecond to again date object
Ankur Parihar
  • 458
  • 6
  • 16
0

The below takes your time string turns it into a date object, gets the milliseconds since the 1. of January 1970 adds 1ms and turns it back into a date object

var newDate = new Date(new Date(lastTimeModified).getTime() + 1)
lusc
  • 1,206
  • 1
  • 10
  • 19