Hướng dẫn php datetime yesterday

You have to compare day with day, secondes comparaison are totally wrong :

If we are today morning, that means yesterday night is today [by minus 24h] ^^

Here a method I use for Kinoulink [ a french startup ] :

public function formatDateAgo[$value]
{
    $time = strtotime[$value];
    $d = new \DateTime[$value];

    $weekDays = ['Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi', 'Dimanche'];
    $months = ['Janvier', 'Février', 'Mars', 'Avril',' Mai', 'Juin', 'Juillet', 'Aout', 'Septembre', 'Octobre', 'Novembre', 'Décembre'];

    if [$time > strtotime['-2 minutes']]
    {
        return 'Il y a quelques secondes';
    }
    elseif [$time > strtotime['-30 minutes']]
    {
        return 'Il y a ' . floor[[strtotime['now'] - $time]/60] . ' min';
    }
    elseif [$time > strtotime['today']]
    {
        return $d->format['G:i'];
    }
    elseif [$time > strtotime['yesterday']]
    {
        return 'Hier, ' . $d->format['G:i'];
    }
    elseif [$time > strtotime['this week']]
    {
        return $weekDays[$d->format['N'] - 1] . ', ' . $d->format['G:i'];
    }
    else
    {
        return $d->format['j'] . ' ' . $months[$d->format['n'] - 1] . ', ' . $d->format['G:i'];
    }
}

Hướng dẫn curl php example

Giới ThiệuCURL là bộ thư viện được sử dụng để giúp thực hiện việc chuyển dữ liệu thông qua nhiều giao thức khác nhau [như HTTP, FPT...]. Với giao thức ...

Hướng dẫn json to php

Chuyển array thành json stringArray thành json string$user = [ id => 1, username => admin, ]; echo json_encode[$user];Kết quả:{id:1,username:admin}Nếu muốn ...

Hướng dẫn get value json php

I have the following JSON format:Nội dung chínhChuyển array thành json stringArray thành json stringChuyển ngược lại json string thành arrayChuyển Object thành json string1. JSON ...

Hướng dẫn dùng upload phot trong PHP

Với mọi trang web đều phải có chức năng upload image lên đưa Database với mục đích thêm hình ảnh vào cơ sở dữ liệu MySQL. Bài viết này sẽ hướng dẫn bạn ...

Hướng dẫn dùng striphtml trong PHP

Hàm strip_tags[] là một hàm có sẵn trong ngôn ngữ PHP được dùng để tách một chuỗi khỏi HTML và các thẻ PHP.Cú pháp:strip_tags[ $str, $allow ];Tham số:$str: Đây là ...

Hướng dẫn php exit vs return

I would like to know in the following case which is a better option:In the PHP script, if the $fileSize variable is larger than 100, I stop the script;Case I:

Chủ Đề