Add date header
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 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()
var header = '# ' + DAYS[date.getDay()] + ' ' + MONTHS[date.getMonth()] + ' ' + date.getDate() + getOrdinal(date.getDate()) + ', ' + date.getFullYear();
editor.setText(editor.getText() + header);