It has to be passed in subtract
a corresponding duration that in your case is 03:00:00
(3 hours) with the command moment.duration
, example :
var value = '/Date(1533227866063)/';
var datetime0 = moment(value)
console.log(datetime0.format("DD/MM/YYYY HH:mm:SS"));
var time = moment.duration("03:00:00");
var datetime1 = moment(value);
datetime1.subtract(time);
console.log(datetime1.format("DD/MM/YYYY HH:mm:SS"));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
It can also be passed through a direct configuration in subtract
a {h:3}
which is the amount of hours, eg:
var value = '/Date(1533227866063)/';
var datetime0 = moment(value)
console.log(datetime0.format("DD/MM/YYYY HH:mm:SS"));
var datetime1 = moment(value);
datetime1.subtract({h:3});
console.log(datetime1.format("DD/MM/YYYY HH:mm:SS"));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
This is very straightforward to what you need to subtract.
Another way is also using the two example parameters:
var value = '/Date(1533227866063)/';
var datetime0 = moment(value)
console.log(datetime0.format("DD/MM/YYYY HH:mm:SS"));
var time = moment.duration("03:00:00");
var datetime1 = moment(value);
datetime1.subtract(3, 'hours');
console.log(datetime1.format("DD/MM/YYYY HH:mm:SS"));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
To add only changes the method but, the form is the same example:
var value = '/Date(1533227866063)/';
var datetime0 = moment(value)
console.log(datetime0.format("DD/MM/YYYY HH:mm:SS"));
var time = moment.duration("03:00:00");
var datetime1 = moment(value);
datetime1.add(3, 'hours');
console.log(datetime1.format("DD/MM/YYYY HH:mm:SS"));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
These are the possible ways to add / subtract with momentjs .
Your documentation has all this explained
moment().add(Number, String);
moment().add(Duration);
moment().add(Object);
moment().subtract(Number, String);
moment().subtract(Duration);
moment().subtract(Object);
The explanation of the parameters is as follows:
|---------------|-------------|
| Key | Shorthand |
|---------------|-------------|
| years | y |
| quarters | Q |
| months | M |
| weeks | w |
| days | d |
| hours | h |
| minutes | m |
| seconds | s |
| milliseconds | ms |
|---------------|-------------|
Examples
moment().add(7, 'days').add(1, 'months');
moment().add({days:7,months:1});
Examples and documentation in: