时间戳转化工具

原先找了个别人写的 Timestamp, 但是用着不方便,转换结果需要粘贴出来才能看到,一般情况下其实只要瞄一眼就好了。于是想让结果直接显示在列表里。

XML

查了下文档 Alfred 只支持 xml 格式的数据来列表展示。发现原来的工具无法兼容。自己写一个:

  • 创建新的 Workflow
  • 右键添加 Inputs -> Script Filter
就用php吧,自带一些文字日期转换
  • 选择语言:Language - php

  • with input as {query}

  • Script:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    $query = '{query}';
    $result = '';

    // If the input is empty or 'now', return the current timestamp.
    if ($query == 'now' || $query == '') {
    $result = @time();
    }

    // If the input is an integer, output the datetime.
    else if (is_numeric($query)) {
    $result = @date('Y-m-d h:i:s', $query);
    }

    // Otherwise, use strtotime to convert the string.
    else {
    $result = @strtotime($query);
    }

    echo '<?xml version="1.0"?>';
    echo '<items>';
    echo '<item uid="timestamp" arg="'.$result.'">';
    echo '<title>结果为: ' .$result. '</title>';
    echo '<subtitle>Press Enter to paste</subtitle>';
    echo '<icon>icon.png</icon>';
    echo '</item>';
    echo '</items>';
  • 粘贴

粘贴
  • 效果
文字转时间戳 Timestamp to string