-
Notifications
You must be signed in to change notification settings - Fork 6
/
timestamp.php
121 lines (110 loc) · 2.96 KB
/
timestamp.php
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
/**
* [CodeZm!] Author CodeZm[codezm@163.com].
*
* 时间戳转换工具
* $Id: timestamp.php 2017-05-20 13:21:25 codezm $
*/
date_default_timezone_set('PRC');
$iconPngUrl = 'icon.png';
if(isset($argv[1])) {
$query = urldecode($argv[1]);
}
if(empty($query)) {
$query = time();
$date = date('Y-m-d', $query);
$time = date('Y-m-d H:i:s', $query);
$outputs = [
'items' => [
[
'arg' => $query,
'title' => $query,
'subtitle' => 'Timestamp - 时间戳',
'icon' => [
'path' => $iconPngUrl
],
'valid' => true,
],
[
'arg' => $date,
'title' => $date,
'subtitle' => 'Date - 日期',
'icon' => [
'path' => $iconPngUrl
],
'valid' => true,
],
[
'arg' => $time,
'title' => $time,
'subtitle' => 'Date/time - 日期时间',
'icon' => [
'path' => $iconPngUrl
],
'valid' => true,
]
]
];
echo json_encode($outputs);
exit;
}
$query = str_replace(array('年', '月', '日', '时', '分', '秒'), array('-', '-', ' ', ':', ':', ':'), $query);
$query = trim($query);
// 非时间格式
if(in_array($query, array('n', 'now'))) {
$query = time();
}
if(!strtotime($query) && strlen(intval($query)) != 10) {
$outputs = [
'items' => [
[
'uid' => '时间格式输入有误',
'arg' => '',
'title' => '请输入时间戳或日期格式',
'subtitle' => '日期/时间字符串 - Power by PHP strtotime Date/Time 函数.',
'icon' => [
'path' => $iconPngUrl
],
'valid' => false
]
]
];
echo json_encode($outputs);
exit;
}
$query = preg_match('/^\d{10}$/', $query) ? $query : strtotime($query);
$date = date('Y-m-d', $query);
$time = date('Y-m-d H:i:s', $query);
$outputs = [
'items' => [
[
'arg' => $query,
'title' => $query,
'subtitle' => 'Timestamp - 时间戳',
'icon' => [
'path' => $iconPngUrl
],
'valid' => true,
],
[
'arg' => $date,
'title' => $date,
'subtitle' => 'Date - 日期',
'icon' => [
'path' => $iconPngUrl
],
'valid' => true,
],
[
'arg' => $time,
'title' => $time,
'subtitle' => 'Date/time - 日期时间',
'icon' => [
'path' => $iconPngUrl
],
'valid' => true,
]
]
];
echo json_encode($outputs);
exit;