日期
输出格式:xxxx年xx月xx日,星期x。如果选中一个数字,则计算并转换为当前日期之前或之后的日期,如果什么都不选,则插入当天日期。

Script key: 输出格式:xxxx年xx月xx日,星期x。如果选中一个数字,则计算并转换为当前日期之前或之后的日期,如果什么都不选,则插入当天日期。

Posted by Chen Yonglin

Install

Details

Label 日期
Voice Over 输出格式:xxxx年xx月xx日,星期x。如果选中一个数字,则计算并转换为当前日期之前或之后的日期,如果什么都不选,则插入当天日期。
Script

//UPDATED. Output format: Weekday, DD-MM-YYYY. If a number is selected, calculates date offset by those many number of days (+ or —). If nothing selected, it outputs the current date

var daysBefore = getSelectedText();
var addDays = -daysBefore;
var nowdate = new Date();
var year = nowdate.getFullYear();
var month = nowdate.getMonth() + 1;
var date = nowdate.getDate();
function computeDate(year, month, day, addDays) {
  dt = new Date(year, month - 1, day);
  baseSec = dt.getTime();
  addSec = addDays * 86400000;
  targetSec = baseSec - addSec;
  dt.setTime(targetSec);
  return dt;
    }
afterDate = computeDate(year, month, date, addDays);
var week = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
var dayOfWeek = week[afterDate.getDay()];

dd = afterDate.getDate()
if(dd<10) {
    dd='0'+dd
} 
mm = afterDate.getMonth() + 1
if(mm<10) {
    mm='0'+mm
} 
yyyy = afterDate.getFullYear()
var buf = yyyy+'年'+mm+'月'+dd+'日'+','+dayOfWeek;

var selRange = getSelectedRange();
setSelectedText(buf);
setSelectedRange(selRange[0]+buf.length, 0);

Advanced

Keyboard shortcut None
Hide key Yes

Discussion

comments powered by Disqus