if text in ('now'): result = datetime.now().strftime('%Y-%m-%d %H:%M:%S') elif text in ('ts', 'timestamp'): result = str(time.time()).split('.')[0] elif match1: timestamp = int(match1.group(0)) timeArray = time.localtime(timestamp) result = time.strftime('%Y-%m-%d %H:%M:%S', timeArray) elif match2: timeArray = time.strptime(text, "%Y-%m-%d %H:%M:%S") result = str(time.mktime(timeArray)).split('.')[0] return result
classTimestampCommand(sublime_plugin.TextCommand): defrun(self, edit): for s in self.view.sel(): if s.empty() or s.size() <= 1: break
# 只处理第一个Region text = self.view.substr(s) print(text)