Hướng dẫn time calculator php - máy tính thời gian php

Xin chào tất cả những gì tôi đang cố gắng tính toán thời gian trôi qua trong PHP. Vấn đề không phải ở PHP, đó là với các kỹ năng toán học của tôi. Ví dụ: Thời gian trong: 11:35:20 (HH: MM: SS), bây giờ nói thời điểm hiện tại là: 12:00:45 (HH: MM: SS) thì chênh lệch thời gian trong công thức của tôi cho đầu ra: 1 : -34: 25. Nó thực sự sẽ là: 25:251:-34:25. It should actually be: 25:25

$d1=getdate();
$hournew=$d1['hours'];
$minnew=$d1['minutes'];
$secnew=$d1['seconds'];

$hourin = $_SESSION['h'];
$secin = $_SESSION['s'];
$minin = $_SESSION['m'];

$h2=$hournew-$hourin;
$s1=$secnew-$secin;
$m1=$minnew-$minin;

if($s1<0) {
    $s1+=60; }
if($s1>=(60-$secin)) {
    $m1--;  }
if($m1<0) {
    $m1++; }
echo $h2 . ":" . $m1 . ":" . $s1;

Xin vui lòng giúp đỡ?

CHỈNH SỬA

Xin lỗi tôi có lẽ đã phải thêm rằng trang làm mới mỗi giây để hiển thị thời gian đã trôi qua mới để tôi phải sử dụng phương thức của mình ở trên. Tôi xin lỗi vì đã không giải thích chính xác.

Hỏi ngày 21 tháng 10 năm 2011 lúc 13:42Oct 21, 2011 at 13:42

Hướng dẫn time calculator php - máy tính thời gian php

WilestwilestWilest

1.7347 Huy hiệu vàng33 Huy hiệu bạc62 Huy hiệu Đồng7 gold badges33 silver badges62 bronze badges

3

Điều này sẽ cung cấp cho bạn số giây giữa bắt đầu và kết thúc.


Để hiển thị nó theo kiểu đồng hồ sau đó, bạn sẽ làm một cái gì đó như thế này:


Nếu bạn không muốn hiển thị các số sau thập phân, chỉ cần thêm round($s); vào đầu hàm secondsToTime().

Đã trả lời ngày 21 tháng 10 năm 2011 lúc 13:44Oct 21, 2011 at 13:44

WwwwwwWWW

9,4541 Huy hiệu vàng27 Huy hiệu bạc32 Huy hiệu đồng1 gold badge27 silver badges32 bronze badges

6

Sử dụng PHP >= 5.3, bạn có thể sử dụng


0 và phương thức của nó

1, trả về một đối tượng

2:

$first  = new DateTime( '11:35:20' );
$second = new DateTime( '12:00:45' );

$diff = $first->diff( $second );

echo $diff->format( '%H:%I:%S' ); // -> 00:25:25

Đã trả lời ngày 21 tháng 10 năm 2011 lúc 13:53Oct 21, 2011 at 13:53

DaBblerdecent DabblerDecent Dabbler

22.1k8 Huy hiệu vàng73 Huy hiệu bạc104 Huy hiệu đồng8 gold badges73 silver badges104 bronze badges

3

Theo dõi thời gian của bạn bằng cách sử dụng hàm 'Time ()'. Sau này bạn có thể chuyển đổi 'Time ()' 'sang các định dạng khác.

$_SESSION['start_time'] = time();

$end_time = time();

$end_time - $_SESSION['start_time'] = 65 seconds (divide by 60 to get minutes)

Và sau đó bạn có thể so sánh điều đó với một giá trị khác sau này.

Sử dụng microtime nếu bạn cần chi tiết mili giây.

Đã trả lời ngày 21 tháng 10 năm 2011 lúc 13:47Oct 21, 2011 at 13:47

donutdan4114donutdan4114donutdan4114

1.2621 Huy hiệu vàng8 Huy hiệu bạc16 Huy hiệu đồng1 gold badge8 silver badges16 bronze badges

1

Bạn có thể thực hiện các giải pháp được hiển thị, nhưng tôi thích sử dụng lớp Phptimer (hoặc các loại khác, bánh xe này đã được phát minh một vài lần). Ưu điểm là bạn thường có thể xác định bộ đếm thời gian để hoạt động hay không, do đó cho phép bạn để lại các cuộc gọi hẹn giờ trong mã của bạn để tham khảo sau mà không cần khóa lại tất cả các điểm thời gian.

Đã trả lời ngày 21 tháng 10 năm 2011 lúc 14:18Oct 21, 2011 at 14:18

Duane Granduane GranDuane Gran

4904 Huy hiệu bạc9 Huy hiệu Đồng4 silver badges9 bronze badges

Xem thảo luận

Cải thiện bài viết

Lưu bài viết

  • Đọc
  • Bàn luận
  • Xem thảo luận

    Cải thiện bài viết

    Lưu bài viết

    Đọc
     

    1. Bàn luận
    2. Cho một mảng chứa thời gian trong HR: Min: SEC định dạng. Nhiệm vụ là tính tổng thời gian. Nếu tổng thời gian lớn hơn 24 giờ thì tổng thời gian sẽ không bắt đầu với 0. Nó sẽ hiển thị tổng thời gian. Có hai cách để tính tổng thời gian từ mảng. & Nbsp; & nbsp;

    Sử dụng hàm strtotime ()strtotime() function: The strtotime() function is used to convert string into the time format. This functions returns the time in h:m:s format.
    Syntax 
     

    strtotime( string )

    Sử dụng hàm explode () This example reads the values from the array and converts it into the time format.
     

    Sử dụng hàm strtotime (): hàm strtotime () được sử dụng để chuyển đổi chuỗi thành định dạng thời gian. Các chức năng này trả về thời gian trong H: M: S định dạng.Syntax & nbsp; & nbsp;

    
    
    3

    Ví dụ 1: Ví dụ này đọc các giá trị từ mảng và chuyển đổi nó thành định dạng thời gian. & NBSP;

    
    
    6
    
    
    7
    
    
    8
    
    
    9
    
    
    8
    
    
    1
    
    
    2

    
    
    6
    
    
    4
    
    
    8
    
    
    6
    
    
    8
    
    
    8
    
    
    2

    
    
    6
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    1

    PHP

    
    
    4
    
    
    5

    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    2

    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    3
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    4
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    5
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    6
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    7
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    8

    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    9
    $_SESSION['start_time'] = time();
    
    $end_time = time();
    
    $end_time - $_SESSION['start_time'] = 65 seconds (divide by 60 to get minutes)
    
    0

    $_SESSION['start_time'] = time();
    
    $end_time = time();
    
    $end_time - $_SESSION['start_time'] = 65 seconds (divide by 60 to get minutes)
    
    1
    $_SESSION['start_time'] = time();
    
    $end_time = time();
    
    $end_time - $_SESSION['start_time'] = 65 seconds (divide by 60 to get minutes)
    
    2
    
    
    4
    $_SESSION['start_time'] = time();
    
    $end_time = time();
    
    $end_time - $_SESSION['start_time'] = 65 seconds (divide by 60 to get minutes)
    
    4
    $_SESSION['start_time'] = time();
    
    $end_time = time();
    
    $end_time - $_SESSION['start_time'] = 65 seconds (divide by 60 to get minutes)
    
    5
    $_SESSION['start_time'] = time();
    
    $end_time = time();
    
    $end_time - $_SESSION['start_time'] = 65 seconds (divide by 60 to get minutes)
    
    6

    array explode( separator, string, limit )
    3

    
    
    6
    $_SESSION['start_time'] = time();
    
    $end_time = time();
    
    $end_time - $_SESSION['start_time'] = 65 seconds (divide by 60 to get minutes)
    
    8
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    4
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    5
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    6
    $_SESSION['start_time'] = time();
    
    $end_time = time();
    
    $end_time - $_SESSION['start_time'] = 65 seconds (divide by 60 to get minutes)
    
    5
    strtotime( string )
    3
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    3
    strtotime( string )
    5

    
    
    6
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    9
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    4
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    9
    array explode( separator, string, limit )
    0
    $_SESSION['start_time'] = time();
    
    $end_time = time();
    
    $end_time - $_SESSION['start_time'] = 65 seconds (divide by 60 to get minutes)
    
    8
    strtotime( string )
    5

    array explode( separator, string, limit )
    4
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    4
    array explode( separator, string, limit )
    6
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    6
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    9
    array explode( separator, string, limit )
    9

    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    9
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    4
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    9 round($s);3
    array explode( separator, string, limit )
    4 round($s);5

    round($s);6

    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    4
    array explode( separator, string, limit )
    6
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    6
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    9 secondsToTime()1

    PHP >= 5.36

    secondsToTime()2

    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    4
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    9 round($s);3round($s);6 secondsToTime()7
    explode() function: The explode() function is used to break a string into an array.
    Syntax 
     

    array explode( separator, string, limit )

    Is This example reads the values from an array and converts it into the time format.
     

    Sử dụng hàm strtotime (): hàm strtotime () được sử dụng để chuyển đổi chuỗi thành định dạng thời gian. Các chức năng này trả về thời gian trong H: M: S định dạng.Syntax & nbsp; & nbsp;

    Ví dụ 1: Ví dụ này đọc các giá trị từ mảng và chuyển đổi nó thành định dạng thời gian. & NBSP;

    PHP

    
    
    6
    
    
    7
    
    
    8
    
    
    9
    
    
    8
    
    
    1
    
    
    2

    
    
    6
    
    
    4
    
    
    8
    
    
    6
    
    
    8
    
    
    12
    
    
    2

    
    
    6
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    1

    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    2

    
    
    4
    
    
    5

    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    2

    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    3
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    4
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    5
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    6
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    7
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    8

    
    
    6
    
    
    17
    
    
    34
    
    
    26
    
    
    36

    
    
    6
    
    
    17
    
    
    34
    
    
    26
    
    
    41

    
    
    6
    
    
    17
    
    
    34
    
    
    26
    
    
    46

    
    
    47
    strtotime( string )
    5

    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    9
    $_SESSION['start_time'] = time();
    
    $end_time = time();
    
    $end_time - $_SESSION['start_time'] = 65 seconds (divide by 60 to get minutes)
    
    0

    $_SESSION['start_time'] = time();
    
    $end_time = time();
    
    $end_time - $_SESSION['start_time'] = 65 seconds (divide by 60 to get minutes)
    
    1
    $_SESSION['start_time'] = time();
    
    $end_time = time();
    
    $end_time - $_SESSION['start_time'] = 65 seconds (divide by 60 to get minutes)
    
    2
    
    
    4
    $_SESSION['start_time'] = time();
    
    $end_time = time();
    
    $end_time - $_SESSION['start_time'] = 65 seconds (divide by 60 to get minutes)
    
    4
    $_SESSION['start_time'] = time();
    
    $end_time = time();
    
    $end_time - $_SESSION['start_time'] = 65 seconds (divide by 60 to get minutes)
    
    5
    $_SESSION['start_time'] = time();
    
    $end_time = time();
    
    $end_time - $_SESSION['start_time'] = 65 seconds (divide by 60 to get minutes)
    
    6

    
    
    6
    $_SESSION['start_time'] = time();
    
    $end_time = time();
    
    $end_time - $_SESSION['start_time'] = 65 seconds (divide by 60 to get minutes)
    
    8
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    4
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    5
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    6
    $_SESSION['start_time'] = time();
    
    $end_time = time();
    
    $end_time - $_SESSION['start_time'] = 65 seconds (divide by 60 to get minutes)
    
    5
    strtotime( string )
    3
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    3
    strtotime( string )
    5

    
    
    6
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    9
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    4
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    9
    array explode( separator, string, limit )
    0
    $_SESSION['start_time'] = time();
    
    $end_time = time();
    
    $end_time - $_SESSION['start_time'] = 65 seconds (divide by 60 to get minutes)
    
    8
    strtotime( string )
    5

    array explode( separator, string, limit )
    4
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    4
    array explode( separator, string, limit )
    6
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    6
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    9
    array explode( separator, string, limit )
    9

    PHP >= 5.36


    $first = new DateTime( '11:35:20' ); $second = new DateTime( '12:00:45' ); $diff = $first->diff( $second ); echo $diff->format( '%H:%I:%S' ); // -> 00:25:25 9 $first = new DateTime( '11:35:20' ); $second = new DateTime( '12:00:45' ); $diff = $first->diff( $second ); echo $diff->format( '%H:%I:%S' ); // -> 00:25:25 4$first = new DateTime( '11:35:20' ); $second = new DateTime( '12:00:45' ); $diff = $first->diff( $second ); echo $diff->format( '%H:%I:%S' ); // -> 00:25:25 9 round($s);3array explode( separator, string, limit )4 round($s);5

    round($s);6

    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    4
    array explode( separator, string, limit )
    6
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    6
    $first  = new DateTime( '11:35:20' );
    $second = new DateTime( '12:00:45' );
    
    $diff = $first->diff( $second );
    
    echo $diff->format( '%H:%I:%S' ); // -> 00:25:25
    
    9 secondsToTime()1Using strtotime() function: The strtotime() function is used to convert string into the time format. This functions returns the time in h:m:s format. Example 1: This example reads the values from the array and converts it into the time format.

    Làm thế nào để PHP tính thời gian thực hiện mã?

    Thời gian đồng hồ có thể sử dụng hàm microtime ().Đầu tiên sử dụng nó trước khi bắt đầu tập lệnh và sau đó ở cuối tập lệnh.Sau đó sử dụng công thức (end_time - start_time).Hàm Mirotime () trả về thời gian tính bằng giây.using microtime() function. First use it before starts the script and then at the end of the script. Then using formula (End_time – Start_time). The mirotime() function returns time in seconds.

    Php tính toán thời gian bắt đầu và kết thúc như thế nào?

    Tính tổng thời gian từ thời gian bắt đầu và kết thúc trong PHP..

    date1 = new DateTime ('2006-04-12T12: 30: 00') ;.

    $ date2 = new DateTime ('2006-04-14t11: 30: 00') ;.

    $ diff = $ date2-> diff ($ date1) ;.

    $ giờ = $ diff-> h ;.

    $ giờ = $ giờ + ($ diff-> ngày*24) ;.

    Làm thế nào tôi có thể tính giờ giữa hai ngày trong PHP?

    Bạn có thể chuyển đổi chúng thành dấu thời gian và đi từ đó: $ hourdiff = vòng ((strtotime ($ time1) - strtotime ($ time2))/3600, 1);$hourdiff = round((strtotime($time1) - strtotime($time2))/3600, 1);