Last active
November 16, 2017 15:28
-
-
Save VasylShevchenko/ec1dc4f528625744a1c7d79a5fc88e6a 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
function putZeroDate(number) { | |
if (number <= 9) { | |
return '0' + number; | |
} | |
return number; | |
} | |
function dateFormat(dateTime) { | |
if (new Date(dateTime) == 'Invalid Date') { | |
return 'Invalid Date' | |
} | |
var dateTime = new Date(dateTime) | |
var day = putZeroDate( dateTime.getDate() ); | |
var month = putZeroDate( dateTime.getMonth() + 1 ); | |
var year = dateTime.getFullYear(); | |
var hours = dateTime.getHours(); | |
var minutes = dateTime.getMinutes(); | |
var seconds = dateTime.getSeconds(); | |
var time = `${day}.${month}.${year} ${hours}:${minutes}:${seconds}` | |
return time; | |
} | |
var date; | |
date = '2017-09-06T13:57:31.313Z'; | |
console.log( dateFormat(date) ); | |
date = new Date(); | |
console.log( dateFormat(date) ); | |
date = '09/09/09'; | |
console.log( dateFormat(date) ); | |
date = 773747399343; | |
console.log( dateFormat(date) ); | |
date = '773747399343'; | |
console.log( dateFormat(date) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment