Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

시간 이쁘게 나타내기!

function timeStamp() {
  var now = new Date();
  var date = [ now.getFullYear(), now.getMonth() + 1, now.getDate() ];
  var time = [ now.getHours(), now.getMinutes(), now.getSeconds() ];
  var suffix = ( time[0] < 12 ) ? "AM" : "PM";
  
  time[0] = ( time[0] < 12 ) ? time[0] : time[0] - 12;
  time[0] = time[0] || 12;
  
  for ( var i = 1; i < 3; i++ ) {
    if ( time[i] < 10 ) {
      time[i] = "0" + time[i];
    }
  }
  return date.join("/") + " " + time.join(":") + " " + suffix;
}

역순 정렬을 위한 꼼수

function timeStamp() {
  var now = new Date();
  return -1 * (now.getTime() - (now.getTimezoneOffset() *1000 * 60));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment