在 php 中获取当前 IST 时间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13340737/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get current IST time in php
提问by user1490612
I am using the following code to get current IST time. But it only gives the system time. I changed my system time due to some reason. So i get only system time instead of current time.
我正在使用以下代码来获取当前的 IST 时间。但它只给系统时间。由于某种原因,我更改了系统时间。所以我只得到系统时间而不是当前时间。
$time_now=mktime(date('h')+5,date('i')+30,date('s'));
$date = date('d-m-Y H:i', $time_now);
echo $date;
回答by deceze
Set your system time correctly, so your system knows its correct timezone and the correct time there. In PHP, set your desired timezone, then just print the date:
正确设置您的系统时间,以便您的系统知道其正确的时区和那里的正确时间。在 PHP 中,设置你想要的时区,然后打印日期:
date_default_timezone_set('Asia/Kolkata');
echo date('d-m-Y H:i');
Don't do manual offset calculations unless you know exactly what you're doing, it's way too fickle.
除非您确切地知道自己在做什么,否则不要进行手动偏移计算,这太善变了。
回答by tarun cool
Get exact Current Indian Time in PHP
在 PHP 中获取准确的当前印度时间
$date = date_default_timezone_set('Asia/Kolkata');
//If you want Day,Date with time AM/PM
echo $today = date("F j, Y, g:i a T");
//Get Only Current Time 00:00 AM / PM
echo $today = date("g:i a");
回答by Lakshya Saini
Use now()method it gave current time.
使用now()方法给出当前时间。
$query = "UPDATE (table name) SET (column) = now()WHERE (condition)";
$query = "UPDATE (表名) SET (column) = now()WHERE (condition)";
Note: Make sure that type of the column in the database must beDATETIMEtype.
注意:确保数据库中列的类型必须是DATETIME类型。
回答by Roey Haim
回答by Adam
Use date_default_timezone_set:
使用date_default_timezone_set:
if (function_exists('date_default_timezone_set'))
{
date_default_timezone_set('Asia/Kolkata');
}
echo date('Y-m-d h-i-s');
回答by Adam
Notice:date_default_timezone_set(): Timezone ID 'Asia/Mumbai'is invalid in D:\Program Files\wamp\www\PHP\...
注意:date_default_timezone_set(): 时区 ID'Asia/Mumbai'在D:\Program Files\wamp\www\PHP\...
Only date_default_timezone_set('Asia/Kolkata')is Showing Valid In PHP 5.4.16 Ver :)
:)
仅date_default_timezone_set('Asia/Kolkata')在 PHP 5.4.16 版本中显示有效 :) :)
回答by SM Imtiaz Hussain
// set the timezone first
if(function_exists('date_default_timezone_set')) {
date_default_timezone_set("Asia/Kolkata");
}
$date = date("m/d/Y");
echo $date;
Before adding the date function use the timezone declaration first.
在添加日期函数之前,首先使用时区声明。
回答by Arun
Set your system time correctly, so your system knows its correct timezone and the correct time there. In PHP, set your desired timezone, then just print the date:
正确设置您的系统时间,以便您的系统知道其正确的时区和那里的正确时间。在 PHP 中,设置你想要的时区,然后打印日期:
date_default_timezone_set('Asia/Kolkata'); echo date('d-m-Y H:i');
date_default_timezone_set('亚洲/加尔各答'); echo date('dmY H:i');

