If you’re using Node.js, you’re sure to have EcmaScript 5, and so Date has a toISOString
method. You’re asking for a slight modification of ISO8601:
new Date().toISOString() > '2012-11-04T14:51:06.157Z'
So just cut a few things out, and you’re set:
new Date().toISOString(). replace(/T/, ' '). // replace T with a space replace(/\..+/, '') // delete the dot and everything after > '2012-11-04 14:55:45'
Or, in one line: new Date().toISOString().replace(/T/, ' ').replace(/\..+/, '')
ISO8601 is necessarily UTC (also indicated by the trailing Z on the first result), so you get UTC by default (always a good thing).
Related Posts:
- How to make a discord bot create an invite for every server it joins?
- map function for objects (instead of arrays)
- Start script missing error when running npm start
- How to you store data for each discord user in the discord server?
- TypeError: Converting circular structure to JSON in nodejs
- Babel 7 – ReferenceError: regeneratorRuntime is not defined
- How do I completely uninstall Node.js, and reinstall from beginning (Mac OS X)
- Getting a UnhandledPromiseRejectionWarning when testing using mocha/chai
- How do I get the current date in JavaScript?
- Client on Node.js: Uncaught ReferenceError: require is not defined
- Error: Can’t set headers after they are sent to the client
- How can a Discord bot create a hyperlink in a Discord message in an embed or in general?
- Get String in YYYYMMDD format from JS date object?
- Getting a UnhandledPromiseRejectionWarning when testing using mocha/chai
- Client on Node.js: Uncaught ReferenceError: require is not defined
- Error: Can’t set headers after they are sent to the client
- TypeError: Router.use() requires middleware function but got a Object
- Express error – TypeError: Router.use() requires middleware function but got a Object
- Cannot GET / Nodejs Error
- Compare two dates with JavaScript
- Compare dates with javascript
- How to set NODE_ENV to production/development in OS X
- Heroku: “No default language could be detected for this app” error thrown for node app
- Heroku: “No default language could be detected for this app” error thrown for node app
- TypeError: Router.use() requires middleware function but got a Object
- How to obtain username from Promise
? - Node.js – SyntaxError: Unexpected token import
- ReferenceError: fetch is not defined
- ‘react-scripts’ is not recognized as an internal or external command
- After $npm install, Getting Error: Cannot find module ‘../lib/utils/unsupported.js’
- SyntaxError: Adjacent JSX elements must be wrapped in an enclosing tag
- Invalid shorthand property initializer
- nodejs – error self signed certificate in certificate chain
- Add days to JavaScript Date
- Parsing a string to a date in JavaScript
- What’s the source of Error: getaddrinfo EAI_AGAIN?
- ReferenceError : window is not defined at object.
Node.js - Why is process.env.NODE_ENV undefined?
- Node.js Port 3000 already in use but it actually isn’t?
- Unable to verify leaf signature
- How can I mock an ES6 module import using Jest?
- AJAX response error: net::ERR_EMPTY_RESPONSE
- Express Render not working return error: No default engine was specified and no extension was provided
- How to use npm jquery module?
- Format JavaScript date as yyyy-mm-dd
- Node.js Error: connect ECONNREFUSED
- TypeError: app.use() requires middleware functions
- No overload matches this call. Type ‘string’ is not assignable to type ‘Signals’
- SyntaxError: Cannot use import statement outside a module
- Node.js document is not defined
- How to handle ETIMEDOUT error?
- How to determine the installed webpack version
- node.js TypeError: path must be absolute or specify root to res.sendFile [failed to parse JSON]
- How to validate date with format “mm/dd/yyyy” in JavaScript?
- XMLHttpRequest module not defined/found
- Expressjs / Node.js – res.redirect() not loading page
- Using async/await with a forEach loop
- Why is my asynchronous function returning Promise {
} instead of a value? - Failed to compile. Module not found: Can’t resolve ‘react-router-dom’
- NodeJs : TypeError: require(…) is not a function
- What is the difference between node.js and io.js?
- module.exports vs exports in Node.js
- Basic Ajax send/receive with node.js
- Cannot find module ‘internal/fs’ after upgrading to node 7
- Npm install cannot find module ‘semver’
- How to download a file with Node.js (without using third-party libraries)?
- Getting current date and time in JavaScript
- How do I remove documents using Node.js Mongoose?
- node-request – Getting error “SSL23_GET_SERVER_HELLO:unknown protocol”
- node-request – Getting error “SSL23_GET_SERVER_HELLO:unknown protocol”
- Shortest way to print current year in a website
- How to fix Cannot find module ‘typescript’ in Angular 4?
- Error: ENOENT: no such file or directory, stat ‘/public/main.html’ at Error (native)
- npm WARN enoent ENOENT: no such file or directory, open ‘C:\Users\Nuwanst\package.json’
- How to access the request body when POSTing using Node.js and Express?
- TypeError: res.json is not a function
- SyntaxError: expected expression, got ‘<'
- Eslint: How to disable “unexpected console statement” in Node.js?
- how to use react require syntax?
- How do you convert a JavaScript date to UTC?
- Convert normal date to unix timestamp
- Maximum call stack size exceeded on npm install
- SyntaxError: Use of const in strict mode
- Check time difference in Javascript
- NPM install fails with node-gyp
- How to convert date to timestamp?
- How to fix Error: listen EADDRINUSE while using NodeJS?
- How to sort in mongoose?
- What counts as CPU Intensive tasks (eg. sorting, searching etc?)
- How to convert binary string to decimal?
- Moment Js UTC to Local Time
- How to disable auto-start of “Node.js: Server-side JavaScript” when using Adobe Dreamweaver?
- Write / add data in JSON file using Node.js
- Make Discord bot send picture with message with NodeJS
- What does `node –harmony` do?
- Get hours difference between two dates in Moment Js
- Javascript: getFullyear() is not a function
- Error: Couldn’t find preset “es2015” relative to directory “/Users/username”
- Using Angular 2 without TypeScript Transpiler
- how to add inside a text box?