PHP: DateTime '-1 day' -
I have to get a date date in a certain time zone. I tried this kind of thing, but it is not working: I still get the date of today. According to this problem, completely using php, depending on the version . In this case, method zodiacing (which is what you are trying to do) is available only on previously connected docs, only PHP version 5.3.0 and above. The mind in it, tells you why your code does not work, and works like @Derrick. If you ever upgrade your PHP version, or your host can upgrade it , You might possibly deduct those three lines in two: No improvement, I know, but the reason is that why it failed to do the job. There are two ways below which I know; A class is created .. which looks much for me until it is nothing different ... second is the composition of a ceremony. Both put some extra lines in something that take less space in one place. Either use is simple; In case of class, this will be something like this. In the case of the function, it will simply ..
class DT {Private $ now; // can be an empty private $ timezone; // datetimejone object public function __conversion ($ tz_str, $ now = null) {$ this- & gt; Now = $ now; $ This- & gt; Timezone = new datetime zone ($ tz_str) ;; } Public function mod ($ mod, $ format) {$ dt = new date time ($ this-> now, $ this- & gt; timezone); $ Dt-> Modified ($ Modern); Return $ dt-> Format ($ format); }} Function mod_formatted_zone ($ tz_str, $ mod, $ format, $ now = null) {$ timezone = new datetime timezone ($ tz_str); $ Dt = new date time ($ now, $ timezone); $ Dt-> Modified ($ Modern); Return $ dt-> Format ($ format); }
$ dt = new DT ('Pacific / Wake'); Echo $ dt-> Mod ('- 1 day', 'Y-M-D');
echo mod_formatted_zone ('Pacific / Wake', '1 day', 'Ym-D ');
Comments
Post a Comment