There is a convenience function in RedBeanPHP ORM for ceating dates.
$time = R::isoDateTime();
How can I set a time zone?
The default function does not return the time of the machine on which RB is running on.
There is a convenience function in RedBeanPHP ORM for ceating dates.
$time = R::isoDateTime();
How can I set a time zone?
The default function does not return the time of the machine on which RB is running on.
It appears from reading the source code, that R::isoDateTime()
is just a convenience method. It simply calls the PHP time()
function, then formats the result as a string using the date
function.
I didn't test it, but in theory - the date_default_timezone_set
function should work. For example:
date_default_timezone_set('America/Los_Angeles');
As Matt pointed out, R::isoDateTime()
is just a convenience function.
In all versions of RedBean I've checked (3.x, 4.x), it is defined as:
@date( 'Y-m-d H:i:s', $time )`
i.e.: a timestamp without any timezone information. e.g.: 2017-09-05 18:49:16.
Under MySQL:
You are probably using datetime
without any timezone information, and R::isoDateTime()
will do just fine.
But pay attention when using Postgres:
Postgres will understand such times, without a timezone, as times in Postgres' timezone (not PHP's!) So even though you set the time using RedBean, you might find out the dates are not what you expected them to be.
This should help:
SHOW timezone;
.ALTER ROLE myuser SET timezone = 'Europe/Paris';
.R::isoDateTime()
you might want to use something like @date( 'c' )
, eg.: 2017-09-05T18:49:16+02:00.And finally keep in mind Postgres stores everything as UTC, but can/will display its timestamp without a time zone
type (AKA timestamptz
) in a variety of timezones, based on its currently-set timezone
setting. e.g.: 2017-09-05T18:49:16+02:00 if Europe/Paris is set, but 2017-09-05T16:49:16+00:00 if UTC is set (both refer to the same time.)
(I love RedBean but haven't seen this covered anywhere. Hopefully this'll help someone.)
© 2022 - 2024 — McMap. All rights reserved.