Created
June 11, 2018 11:36
-
-
Save dominikbulaj/27bcb71acb90f31acfa3a5c8e774a717 to your computer and use it in GitHub Desktop.
MySQL DATETIME to JavaScript Date
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
// example MySQL DATETIME | |
const dateTime = '2017-02-04 11:23:54'; | |
let dateTimeParts= dateTime.split(/[- :]/); // regular expression split that creates array with: year, month, day, hour, minutes, seconds values | |
dateTimeParts[1]--; // monthIndex begins with 0 for January and ends with 11 for December so we need to decrement by one | |
const dateObject = new Date(...dateTimeParts); // our Date object |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment