D
D
Denis2017-10-09 08:14:31
Yii
Denis, 2017-10-09 08:14:31

How to get the date and time of the user in PHP in Yii2 without using JavaScript?

In Yii2 I use Kartik's DateTimePicker widget, pass the user's date and time: As I understand it, I get server time that is 1 hour behind my time... How can I get the current time and date of the user's computer without using JavaScript? Help with code please.
'options'=>['value' => date("d.m.Y H:i:s")]

Answer the question

In order to leave comments, you need to log in

4 answer(s)
E
Evgeny Kalibrov, 2017-10-09
@rework

On the server, it's better to work with a single server time zone (preferably UTC), and do all the formatting and time conversion to the desired time zone on the client. For these purposes, I usually start a constant somewhere in the global scope of the JS script, which stores the offset of the user's time zone relative to UTC, and this constant is used wherever the date / time is displayed.

D
Dmitry, 2017-10-09
@slo_nik

Good morning.
Set the time zone in the configuration file and everything will be fine.
How to work with date and time in js.

M
Maxim Fedorov, 2017-10-09
@qonand

How to get the current time and date of the user's computer without using JavaScript?

No way. PHP is a server language, and it has nothing to do with what happens on the client machine. To work with the client machine, there is JavaScript. What's the problem with using it?

A
Alexander Urich, 2017-10-13
@Urichalex

You can find out the time zone by the client's IP

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question