简体   繁体   中英

Inserting timestamp in MySQL

When I am inserting a time field in the database table, it inserts with a proper time and date in localhost and I can retrieve a correct time. BUT The same code when I upload it in the server(Godaddy), the value in the database field will insert "30 minutes less than the actual time".

What may be the reason?

You just add this line at the top of your php file to set timezone.... Try this code:

<?php
   date_default_timezone_set("Asia/Kolkata");
   echo date("Y/m/d H:i:s");
 ?>

Use the code below to convert GoDaddy server time to Indian time.

$timestamp = strtotime($time) + 49000;

Where $time is the server production time and $timestamp is the new time generated.

Please Try this

<?php
  date_default_timezone_set('Asia/Kolkata');
  echo date_default_timezone_get(), '--', date("Y-m-d g:i:a"),'<br />';
?> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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