time.js 935 B

123456789101112131415161718192021222324252627282930
  1. ///import core
  2. ///import plugins\inserthtml.js
  3. ///commands 日期,时间
  4. ///commandsName Date,Time
  5. ///commandsTitle 日期,时间
  6. /**
  7. * 插入日期
  8. * @function
  9. * @name baidu.editor.execCommand
  10. * @param {String} cmdName date插入日期
  11. * @author zhuwenxuan
  12. */
  13. /**
  14. * 插入时间
  15. * @function
  16. * @name baidu.editor.execCommand
  17. * @param {String} cmdName time插入时间
  18. * @author zhuwenxuan
  19. */
  20. UE.commands['time'] = UE.commands["date"] = {
  21. execCommand : function(cmd){
  22. var date = new Date;
  23. this.execCommand('insertHtml',cmd == "time" ?
  24. (date.getHours()+":"+ (date.getMinutes()<10 ? "0"+date.getMinutes() : date.getMinutes())+":"+(date.getSeconds()<10 ? "0"+date.getSeconds() : date.getSeconds())) :
  25. (date.getFullYear()+"-"+((date.getMonth()+1)<10 ? "0"+(date.getMonth()+1) : date.getMonth()+1)+"-"+(date.getDate()<10?"0"+date.getDate():date.getDate())));
  26. }
  27. };