Last active
March 3, 2019 00:46
-
-
Save spencerfeng/e04003e3d9f418745363cd78f1976767 to your computer and use it in GitHub Desktop.
This file contains 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
import moment from 'moment'; | |
const originalDateString = '06/03/2019'; | |
const date = moment(originalDateString, 'DD/MM/YYYY'); | |
//-------------------------------------------------------------- | |
// Convert date string in DD/MM/YYYY format to YYYY-MM-DD format | |
//-------------------------------------------------------------- | |
const convertedDateString1 = date.format('YYYY-MM-DD'); | |
// console.log(convertedDateString1) '2019-03-06' | |
//-------------------------------------------------------------- | |
// Convert date string in DD/MM/YYYY format to YYYY-M-D format | |
//-------------------------------------------------------------- | |
const convertedDateString2 = date.format('YYYY-M-D'); | |
// console.log(convertedDateString2) '2019-3-6' | |
//-------------------------------------------------------------- | |
// Convert date string in DD/MM/YYYY format to MM/DD/YYYY format | |
//-------------------------------------------------------------- | |
const convertedDateString3 = date.format('MM/DD/YYYY'); | |
// console.log(convertedDateString3) '03/06/2019' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment