Hướng dẫn dùng singapur timezone trong PHP

I wants to display singapore time. I have tried out like this,

but when inserting this value to a column of data table (with datatype-datetime ) it shows the time as 0000-00-00 00:00:00. Please help

asked Jan 21, 2014 at 7:20

You need to insert with mysql date time format. In PHP which is equivalent to,

date("Y-m-d H:i:s")

Note: Issue is not related to Time Zone, but you can set default time zone to Singapore using date_default_timezone_set('Asia/Singapore'); on top of your file.

answered Jan 21, 2014 at 7:23

Hướng dẫn dùng singapur timezone trong PHP

RikeshRikesh

25.8k14 gold badges77 silver badges86 bronze badges

1

date_default_timezone_set('Asia/Singapore');

look at this for default_time_rimezone

to get the timezone.

answered Jan 21, 2014 at 7:32

Hướng dẫn dùng singapur timezone trong PHP

KaushikKaushik

2,0241 gold badge22 silver badges29 bronze badges

There are two methods to display current timestamp. Either you use "localtime" PHP method to display the current local time in an Array OR you can use DateTimeZone to display the specific timezone date-time. Here is the code ..

setTimezone($to); echo $currDate->format('Y/m/j H:i:s'); ?>

answered Jan 21, 2014 at 7:37

AJ101AJ101

691 silver badge8 bronze badges

date_default_timezone_set('Asia/Singapore');
$todayDate=date("Y-m-d H:i:s");

answered Aug 17, 2021 at 13:02

Hướng dẫn dùng singapur timezone trong PHP

write date_default_timezone_set('Asia/Singapore'); before displaying the date.

for inputting the value into database, use the date("Y-m-d H:i:s") format in php to match the column, or make the column type as varchar(50) to store date as string.

answered Jan 21, 2014 at 7:27

ArcherArcher

1,1424 gold badges12 silver badges34 bronze badges

You can use this

http://ir2.php.net/manual/en/datetime.construct.php

// Current date/time in the specified time zone. $date = new DateTime(null, new DateTimeZone('Asia/Singapore')); echo $date->format('Y-m-d H:i:sP') . "\n";

answered Jan 21, 2014 at 7:32

farzamfarzam

6992 gold badges6 silver badges19 bronze badges

try with date_default_timezone_set()

answered Jan 21, 2014 at 7:33

Not the answer you're looking for? Browse other questions tagged php or ask your own question.