Last active
July 15, 2020 16:13
-
-
Save Alexisvt/c857922ceba46e9a2b5335296b70315d to your computer and use it in GitHub Desktop.
Code snippet showing how to transform a regular date to UTC and vice versa.
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
const moment = require('moment'); | |
const regularDate = moment() // ? | |
const regularDateString = regularDate.format('YYYY-mm-DD HH:ss'); // ? | |
const utcDate = moment.utc() // ? | |
const utcString = utcDate.format('YYYY-mm-DD HH:ss') //? | |
// transforming regular to UTC | |
console.log(moment.utc(regularDate).format('YYYY-mm-DD HH:ss')) // ? | |
console.log(moment(regularDateString, 'YYYY-mm-DD HH:ss').utc().format('YYYY-mm-DD HH:ss')) // ? | |
// UTC to regular | |
moment.utc(utcDate).local().format('YYYY-mm-DD HH:ss'); // ? | |
moment.utc(utcString, 'YYYY-mm-DD HH:ss').local().format('YYYY-mm-DD HH:ss'); // ? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment