gpt4 book ai didi

php - php中的印度日期和时间

转载 作者:行者123 更新时间:2023-12-04 17:18:49 25 4
gpt4 key购买 nike

伙计们,我试图在 PHP 中获得正确的印度时间和日期

我试过这个代码:

$date = date("d/m/Y");
$date1 = date("H:i a");

if(function_exists('date_default_timezone_set'))
{
date_default_timezone_set("Asia/Kolkata");
}

echo $date;
echo $date1;

但我没有得到正确的时间。我得到的时间是 4.30晚了几个小时。我的代码有什么错误吗?

最佳答案

在使用任何日期函数之前先声明时区:

// set the timezone first
if(function_exists('date_default_timezone_set')) {
date_default_timezone_set("Asia/Kolkata");
}

// then use the date functions, not the other way around
$date = date("d/m/Y");
$date1 = date("H:i a");

echo $date . '<br/>';
echo $date1;

关于php - php中的印度日期和时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26670210/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com