Created
August 31, 2017 15:17
-
-
Save franbcn93/6f1c6ce37854a98e6dbc1c832ce2b5a1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var express = require ('express'); | |
| var bodyParser = require('body-parser'); | |
| var cors = require('cors'); | |
| var app = module.exports = express(); | |
| app.use(bodyParser.json()); | |
| app.use(cors()); | |
| app.get('/dateValues/:dateVal', function(req,res,next){ | |
| var dateVal = req.params.dateVal; | |
| var dateFormattingOptions = { | |
| year: 'numeric', | |
| month: 'long', | |
| day: 'numeric' | |
| }; | |
| if(isNaN(dateVal)){ | |
| var naturalDate = new Date (dateVal); | |
| naturalDate = naturalDate.toLocaleDateString('en-us', dateFormattingOptions); | |
| var unixDate = new Date (dateVal).getTime()/1000; | |
| } | |
| else{ | |
| var unixDate = dateVal; | |
| var naturalDate = new Date(dateVal*1000); | |
| naturalDate = naturalDate.toLocaleDateString('en-us', dateFormattingOptions); | |
| } | |
| res.json({unix: unixDate, natural: naturalDate}); | |
| }); | |
| app.listen(3000, function(){ | |
| console.log("It's Working"); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Folder |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment