简体   繁体   English

在php中获取当前的IST时间

[英]Get current IST time in php

I am using the following code to get current IST time. 我使用以下代码来获取当前的IST时间。 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. 所以我只得到系统时间而不是当前时间。

$time_now=mktime(date('h')+5,date('i')+30,date('s'));
$date = date('d-m-Y H:i', $time_now);
echo $date;

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. 除非你确切知道自己在做什么,否则不要进行手动偏移计算,这样做太过于善变。

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");

Use now() method it gave current time. 使用now()方法给出当前时间。

$query = "UPDATE (table name) SET (column) = now() WHERE (condition)"; $ query =“UPDATE(表名)SET(列)= now() WHERE(条件)”;

Note : Make sure that type of the column in the database must be DATETIME type. 注意确保数据库中列的 类型 必须为 DATETIME 类型。

To get the user current time you will need javascript. 要获得用户当前时间,您需要使用javascript。 if you want to make default timezone on your pages you can use date_default_timezone_set 如果要在页面上设置默认时区,可以使用date_default_timezone_set

You can read about this in: HERE 你可以在这里读到: HERE

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');

Notice: date_default_timezone_set() : Timezone ID 'Asia/Mumbai' is invalid in D:\\Program Files\\wamp\\www\\PHP\\... 注意: date_default_timezone_set() :时区date_default_timezone_set() 'Asia/Mumbai'D:\\Program Files\\wamp\\www\\PHP\\...无效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 Ver :)中显示有效:)

// 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. 在添加日期函数之前,请先使用时区声明。

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'); date_default_timezone_set( '亚/加尔各答'); echo date('dmY H:i'); 回音日期('dmY H:i');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM