Moment.js Why do I get different values in Unix Timestamp format in the "same" input values?

I have a simple code that implements a Timestamp API. It accepts the date as a string MMMM-DD-YYYY or in the form of a Unix Timestamp converts and returns, respectively, MMMM-DD-YYYY or Unix Timestamp

var express = require('express');
var moment = require('moment');
var url = require('url');
var cors = require('cors');
var port = process.env.PORT || 8080;

var app = express();
app.use(cors());

app.route('/').get(function (req, res) {
 Res. sendFile(process.cwd() + '/index.html')
});

app.get('/:date', function(req, res) {

 var URL = url.parse(req.url).pathname.replace(/%20/g, ' ').slice(1);

 if (isNaN(URL)) {
 var unixtime = moment(URL, "LL").unix()
 var naturaltime = moment(URL, "LL").format("LL")
 } else {
 var unixtime = moment.unix(URL, "LL").unix()
 var naturaltime = moment.unix(URL).format("LL")
}

Res. send(JSON.stringify({
 unix : unixtime,
 natural : naturaltime
}))

});

app.listen(port, function() {
 console.log('Node.js listening on port' + port)
});


When I give my query a unix timestamp. for example

http://localhost:8080/1450137600

I receive the following object

{
 unix: 1450137600,
 natural: "December 15, 2015"
}


But if you send for example the same December 15, 2015

http://localhost:8080/December 15, 2015

You'll get

{
 unix: 1450098000,
 natural: "December 15, 2015"
}


And

http://localhost:8080/1450098000

{
 unix: 1450098000,
 natural: "December 15, 2015"
}


Why for the same input values, I get different unix timestamp ? While he and the other timestamp represent the same date, December 15, 2015
July 8th 19 at 15:28
1 answer
July 8th 19 at 15:30
Solution
UTC
try this:
if (isNaN(URL)) {
var unixtime = moment.utc(URL, "LL").unix()
var naturaltime = moment.utc(URL, "LL").format("LL")
} else {
var unixtime = moment.unix(URL, "LL").unix()
var naturaltime = moment.unix(URL).format("LL")
} - Frederique_Yundt19 commented on July 8th 19 at 15:33

Find more questions by tags Work with date / timeJavaScriptNode.js