├── README.md ├── microtime.php ├── time conversion.alfredworkflow ├── time.php ├── ts.png ├── ts_time.png ├── tsm.png └── workflows.php /README.md: -------------------------------------------------------------------------------- 1 | ## time conversion alfredworkflow是什么? 2 | 3 | 基于PHP开发的alfredworkflow,用于`时间戳`和`格式化时间`的相互转换。 4 | 5 | [新工具,结合时间转换和变量转换](https://github.com/kangzhi2016/conversion-tools) 6 | 7 | ## 安装方法: 8 | 9 | * 1.先安装[Alfred](https://www.alfredapp.com/),已安装的直接第2步。 10 | * 2.git clone 或直接点击此处[下载](https://github.com/kangzhi2016/time-conversion-alfredworkflow/releases) 11 | * 3.下载完成后,解压,双击文件夹中的time conversion.alfredworkflow安装即可。 12 | 13 | ## 使用说明: 14 | 15 | * 1.默认在alfred搜索框中输入关键字 “ts” ,显示当前时间戳和格式化后的时间。 16 | 17 | * ![ts.png](./ts.png) 18 | 19 | * 2.在关键字 “ts”后输入**空格**+要转换的时间,即可在列表中得到想要的时间格式,选中想要的格式,回车就复制到剪切板了。 20 | 21 | * ![ts time.png](./ts_time.png) 22 | 23 | * 3.新增 13 位微妙时间戳,用法同上,只是关键字为 “tsm”。 24 | 25 | * ![tsm.png](./tsm.png) 26 | 27 | ##有问题反馈 28 | 在使用中有任何问题,欢迎反馈给我,可以用以下联系方式跟我交流 29 | 30 | * QQ: 1563659827 31 | * 邮件: 1563659827@qq.com 32 | * 简书: [@拿破仑蛋糕](https://www.jianshu.com/u/ba651d19aa1f) 33 | 34 | -------------------------------------------------------------------------------- /microtime.php: -------------------------------------------------------------------------------- 1 | getMsecTime(); 10 | $sub_title = $this->getMsecToMescdate($title); 11 | 12 | set_result(1, $title, $title, $sub_title, 'icon.png'); 13 | set_result(2, $sub_title, $sub_title, $title, 'icon.png'); 14 | }else{ 15 | if(is_numeric($string) && strlen($string) == 13){ 16 | $title = $this->getMsecToMescdate($string); 17 | }else{ 18 | $title = $this->getDateToMesc($string); 19 | } 20 | 21 | set_result(1, $title, $title, $string, 'icon.png'); 22 | } 23 | 24 | echo_result(); 25 | } 26 | 27 | /** 28 | * 获取毫秒级别的时间戳 29 | */ 30 | public function getMsecTime() 31 | { 32 | list($msec, $sec) = explode(' ', microtime()); 33 | return (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000); 34 | } 35 | 36 | /** 37 | * 毫秒转日期 38 | */ 39 | public function getMsecToMescdate($msectime) 40 | { 41 | $msectime = $msectime * 0.001; 42 | if(strstr($msectime,'.')){ 43 | list($usec, $sec) = explode(".",$msectime); 44 | $sec = str_pad($sec,3,"0",STR_PAD_RIGHT); 45 | }else{ 46 | $usec = $msectime; 47 | $sec = "000"; 48 | } 49 | $date = date("Y-m-d H:i:s.x",$usec); 50 | return str_replace('x', $sec, $date); 51 | } 52 | 53 | /** 54 | * 日期转毫秒 55 | */ 56 | public function getDateToMesc($mescdate) 57 | { 58 | list($usec, $sec) = explode(".", $mescdate); 59 | $date = strtotime($usec); 60 | return str_pad($date.$sec,13,"0",STR_PAD_RIGHT); 61 | } 62 | } 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /time conversion.alfredworkflow: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kangzhi2016/time-conversion-alfredworkflow/91f415e296de8534dff9fa1a9d786a6a8c0f316b/time conversion.alfredworkflow -------------------------------------------------------------------------------- /time.php: -------------------------------------------------------------------------------- 1 | $uid, 11 | 'arg' => $arg, 12 | 'title' => $title, 13 | 'subtitle' => $sub, 14 | 'icon' => $icon 15 | ); 16 | 17 | $GLOBALS['result']['items'][] = $item; 18 | } 19 | 20 | function echo_result() 21 | { 22 | echo json_encode($GLOBALS['result']); 23 | } 24 | --------------------------------------------------------------------------------