本文介绍了在php中检查一年的季节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一年中的每个季节打印不同的图像.基于我数据库中的日期.我想将其打印在php/html5中.

I want to print a different image every season of the year. Based on a date from my database. I want to print it in php/html5.

在互联网上找到了一些东西,但没有一个与我的数据库日期配合使用.

Found some things on the internet but none of them worked with my database date.

推荐答案

只需格式化与您匹配的值

Just need to format the values o match yours

$someDay = "2018-12-01";

$spring = (new DateTime('March 20'))->format("Y-m-d");
$summer = (new DateTime('June 20'))->format("Y-m-d");
$fall = (new DateTime('September 22'))->format("Y-m-d");
$winter = (new DateTime('December 21'))->format("Y-m-d");

switch(true) {
    case $someDay >= $spring && $someDay < $summer:
        echo 'It\'s Spring!';
        break;

    case $someDay >= $summer && $someDay < $fall:
        echo 'It\'s Summer!';
        break;

    case $someDay >= $fall && $someDay < $winter:
        echo 'It\'s Fall!';
        break;

    default:
        echo 'It must be Winter!';
}

这篇关于在php中检查一年的季节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 05:56