Skip to content

Instantly share code, notes, and snippets.

@EtherDream
Created March 15, 2018 08:55
Show Gist options
  • Save EtherDream/b54596c609e3bc44150d4b4c3028829d to your computer and use it in GitHub Desktop.
Save EtherDream/b54596c609e3bc44150d4b4c3028829d to your computer and use it in GitHub Desktop.
date object -> "yyyy/MM/dd hh/mm/ss"
function formatTime(date) {
var d = new Date(date - 60000 * date.getTimezoneOffset());
var s = d.toISOString();
return s.substr(0, 10) + ' ' + s.substr(11, 8);
}
formatTime( new Date() ); // "2018-03-15 16:52:34"
@EtherDream
Copy link
Author

EtherDream commented Mar 15, 2018

const formatTime = date =>
  new Date(date - 60000 * date.getTimezoneOffset())
    .toISOString()
    .substr(0, 19)
    .replace('T', ' ');
formatTime( new Date() );   // "2018-03-15 16:59:40"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment