-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.php
More file actions
53 lines (48 loc) · 1.33 KB
/
demo.php
File metadata and controls
53 lines (48 loc) · 1.33 KB
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
<?php
require 'TimeZoneConversion.php';
TestConvert();
TestTimestampConvert();
// 测试日期时间时区转换
function TestConvert()
{
$cases = array(
array(
'ori_datetime' => '2024-07-15 21:00:00',
'ori_timezone' => 'GMT+0800',
'dest_timezone' => 'GMT+0700',
'dest_format' => 'Y-m-d H:i:s',
),
array(
'ori_datetime' => '2024-07-15 22:00:00',
'ori_timezone' => 'GMT+0000',
'dest_timezone' => 'GMT+0800',
'dest_format' => 'Y-m-d H:i:s',
),
);
foreach($cases as $case)
{
$resp = TimeZoneConversion::convert($case['ori_datetime'], $case['ori_timezone'], $case['dest_timezone'], $case['dest_format']);
print_r($resp);
}
}
// 测试时间戳时区转换
function TestTimestampConvert()
{
$cases = array(
array(
'timestamp' => 1721120701,
'timezone' => 'GMT+0700',
'format' => 'Y/m/d/ H:i:s \G\M\TO',
),
array(
'timestamp' => 1721120701,
'timezone' => 'GMT+0630',
'format' => 'Y/m/d/ H:i:s \G\M\TO',
),
);
foreach($cases as $case)
{
$resp = TimeZoneConversion::timestampConvert($case['timestamp'], $case['timezone'], $case['format']);
echo $resp.PHP_EOL;
}
}