Add date header
Shared by Kubisuro
Append a markdown header with the current date. Useful when writing a journal.
Script
var MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var DAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
function addZero(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}
function getOrdinal(x) {
if (x == 1) {
return 'st'
} else if (x == 2) {
return 'nd'
} else if (x == 3) {
return 'rd'
} else {
return 'th'
}
}
var date = new Date()
dayNum = addZero(date.getDate())
var header = '# ' + DAYS[date.getDay()] + ' ' + dayNum + ' ' + ' ' + MONTHS[date.getMonth()] + ' ' + date.getFullYear();
editor.setText(editor.getText() + header);