PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label timezone. Show all posts
Showing posts with label timezone. Show all posts

Sunday, November 13, 2022

[FIXED] How to upgrade timezonedb/timelib on php7 (plesk onyx)?

 November 13, 2022     pecl, php, plesk, timezone, timezonedb     No comments   

Issue

im using PHP Version 7.0.31 on a Plesk Onyx system.

phpinfo() is showing me:

date
date/time support: enabled
timelib version: 2016.02
"Olson" Timezone Database Version   0.system
Timezone Database   internal
Default timezone    Europe/Berlin

The used timelib version "2016.02" is outdated so i need to upgrade it to the current version 2018.5 (https://pecl.php.net/package/timezonedb).

How to do that? "pecl upgrade timezonedb" didn't worked out and after hours of googling and trying i'm clueless...


Solution

Context

I've solved a similar problem in my company, but related to daylight saving time in Brazil. The time was 1 hour wrong in all our servers that uses PHP 7.0.32, while the servers that uses PHP 7.1 are working fine.

Our servers are running on AWS EC2 instances. Our timezone is America/Sao_Paulo. It's important to note that our main goal was "update timelib PHP extension", but we found that was not needed, since updating the timezone database version was enough to solve our problem.

Solution

In order to solve that outdated datetime, I've run the following commands from SSH, logged in as root user:

pecl7 install timezonedb

After that, we need to add the extension to our PHP.INI file. In my case it was loaded and located from /etc/php.ini. To check yours, just create a phpinfo.php file and check from which location your machine is loading the php.ini file:

enter image description here

Then, just run somewhat like:

nano /etc/php.ini

And then add the following line to the last line of your php.ini file:

extension=timezonedb.so

In order to check if the update has made sucessfully, restart php / php-fpm with the following command:

service php-fpm restart

Then, let's access again the PHPINFO and...

enter image description here



Answered By - Paladini
Answer Checked By - Robin (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Wednesday, August 31, 2022

[FIXED] How to get timezone hour offset and account for DST with PEAR::Date?

 August 31, 2022     dst, pear, php, timezone     No comments   

Issue

I am trying to get the offset hours from UTC, given a summer date. My system time is set to America/Los_Angeles.

I have the following:

require_once("Date.php");

$dateTZ = new Date_TimeZone('America/Los_Angeles');

echo $dateTZ->getOffset(new Date('2009-07-01 12:00:00'))/1000/60/60;

This prints '-8'; shouldn't it show '-7'?

echo $dateTZ->getOffset(new Date())/1000/60/60;

also prints '-8'.

What am I doing wrong?


Solution

Does Date::inDaylightTime() help you? Date::getTZOffset claims to include daylight savings offset.



Answered By - cletus
Answer Checked By - Cary Denson (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Thursday, August 11, 2022

[FIXED] How to Convert DateTime.Now in 0 to 1 decimal format in c#

 August 11, 2022     c#, datetime, decimal, format, timezone     No comments   

Issue

I would like to convert the current time to a decimal representing a fraction of the day. For example, if the day starts at 0, then 12:00 PM should be 0.5.

I need to send that value to an API, and it needs to be in that format. i.e.

"LAST_PRINT_TIME":0.22020833"

Solution

Depending on the precision requirements of your result, this may help you:

DateTime now = DateTime.Now;
double dayFraction = (now.Hour + now.Minute / 60d) / 24d;

now.Minute / 60d calculates the fraction of the current hour (so if the time is XX:15 PM this will give 0.25). This is then added to the current hour. This value is then divided by 24 to obtain the final result.

For example, 3:45 PM would go as follows: (15 + 45 / 60) / 24) => (15 + 0.75) / 24 => 15.75 / 24 => 0.65625

So 3:45 PM, which is 15.75 hours into the day, would be 0.65625 (or 65.625%) of the day.


Or, as @madreflection mentioned in a comment, you could use .ToOADate() as well. In this case, you could do something like:

DateTime now = DateTime.Now;
double dayFraction = now.ToOADate() - now.Date.ToOADate();


Answered By - elmer007
Answer Checked By - Robin (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Sunday, July 17, 2022

[FIXED] How to disable R warning: timezone of object (UTC) is different than current timezone ()

 July 17, 2022     r, timezone, warnings     No comments   

Issue

I keep getting this warning: timezone of object (UTC) is different than current timezone (). My current timezone is "EET", as shown by Sys.timezone().

Is there a way to change the R timezone to UTC, instead of it taking the one from my system? Or to disable the warning?


Solution

Try this:

Sys.setenv(TZ = "UTC")


Answered By - G. Grothendieck
Answer Checked By - Cary Denson (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Monday, March 14, 2022

[FIXED] Symfony - MAMP(windows) - warning timezone

 March 14, 2022     ini, mamp, php, symfony, timezone     No comments   

Issue

I installed MAMP for windows

I have this error since several hours...

    [Symfony\Component\Debug\Exception\ContextErrorException]                   
 Warning: date_default_timezone_get(): It is not safe to rely on the system' 
 s timezone settings. You are *required* to use the date.timezone setting or 
  the date_default_timezone_set() function. In case you used any of those me 
 thods and you are still getting this warning, you most likely misspelled th 
 e timezone identifier. We selected the timezone 'UTC' for now, but please s 
 et date.timezone to select your timezone.

In the php.ini concerned (C:/MAMP/conf/php5.5.19/php.ini), I changed the line DATE like this:

    [Date]
; Defines the default timezone used by the date functions
date.timezone = "Europe/Paris"

And in my phpinfo(), the path loaded is :

Loaded Configuration File   C:\MAMP\conf\php5.5.19\php.ini

When I do in the consol the command php --ini I have this :

C:\Users\Thomas>php --ini
Configuration File (php.ini) Path: C:\Windows
Loaded Configuration File: (none)
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)

Why Configuration File (php.ini) Path: is "C:\Windows" and not C:\MAMP\conf\php5.5.19\. Can I change this Path ?

I don't know what to do now...

thanks !


Solution

I had the same error. I had no clue where it was coming from, but with some trial and error I figured out it had something to do with the special character in my htdocs folder:

htdocs/Exámple

By changing that character to a normal character (thus changing to htdocs/Example), I no longer got the error and the site would load normally.



Answered By - Maarten
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Friday, February 18, 2022

[FIXED] phpinfo displays date.timezone warning in MAMP

 February 18, 2022     mamp, php, phpinfo, timezone     No comments   

Issue

I ran a phpinfo() function in MAMP, and received the following warning, embedded in the php info table:

Warning: phpinfo() [function.phpinfo]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/New_York' for 'EST/-5.0/no DST' instead in /Applications/MAMP/bin/mamp/phpinfo.php on line 2 

the date.timezone in the php.ini file is set to 'America/New_York', and the warning is only three rows above that actual setting reflected in the phpinfo table!

Could someone please explain to me how to fix this issue?


Solution

You're certain there are no quotes around the timezone in the .ini file?

date.timezone = America/New_York

http://www.php.net/manual/en/timezones.america.php#85815



Answered By - depwl9992
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Sunday, February 6, 2022

[FIXED] date_default_timezone_get(): It is not safe to rely on the system's timezone settings

 February 06, 2022     php, symfony, timezone     No comments   

Issue

Can anyone tell me why am I getting this error when running app/console in a brand new formatted macbook with the latest MAMP installed ?

Warning: date_default_timezone_get(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Helsinki' for 'EEST/3.0/DST' instead in /../Logger.php line 112

I have checked the path of php.ini and marked out the date.timezone = "Europe/Athens"

Also restarted MAMP/apache several times.


Solution

Default php.ini in OS X is located at:

/private/etc/php.ini

Anyway, you'll can either tell CLI php to load MAMP settings, or use an alias of MAMP command itself.



Answered By - moonwave99
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Wednesday, January 26, 2022

[FIXED] Carbon auto increments time by 11 minutes on parse

 January 26, 2022     laravel, laravel-5, php-carbon, timezone, timezone-offset     No comments   

Issue

I am using Carbon with Laraveal, my local timezone is in IST. I am passing the below ISO string from the UI.

2019-11-22T03:00:00.000Z

When parsed on the server with the below syntax:

\Carbon\Carbon::parse($value)->timezone($this->user->timezone)->format('Y-m-d H:m:s');

The output I am getting is :

2019-11-22 03:11:00

Don't know why I am getting the additional 11 minutes in the time. UI and Server both runs in my local machine. Don't know what's causing the 11 minutes addition.


Solution

->format('Y-m-d H:m:s');

should be

->format('Y-m-d H:i:s');

Notice the m for months and i for minutes.

See PHP docs for formats



Answered By - KFoobar
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing