Skip to content

Instantly share code, notes, and snippets.

@cssmagic
Created December 12, 2014 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cssmagic/8d22e51b281ca41e2f8a to your computer and use it in GitHub Desktop.
Save cssmagic/8d22e51b281ca41e2f8a to your computer and use it in GitHub Desktop.
GitHub Issue 显示标准化的时间格式
$('div[id^=issuecomment-]').each(function () {
var $header = $(this).find('.timeline-comment-header-text')
var time = $header.find('time').attr('datetime')
var date = new Date(time)
var year = date.getFullYear()
var month = format(date.getMonth() + 1)
var day = format(date.getDate())
var hour = format(date.getHours())
var min = format(date.getMinutes())
var sec = format(date.getSeconds())
var fullTime = [year, month, day].join('-') + ' ' + [hour, min, sec].join(':')
// console.log(fullTime)
var author = $header.find('.author').html()
$header.html('@' + author + ' - ' + fullTime)
})
function format(i) {
return i > 9 ? i : '0' + i
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment