Unable to get the local time in a script

The forum for designers and developers.
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
User avatar
bertkessels
Posts: 15
Joined: 6. Nov 05, 14:05
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Unable to get the local time in a script

Postby bertkessels » 13. Apr 08, 21:35

In a script I use the Date() constructor to get the current date and time.
As it turns out, this results in the GMT date/time (universal time).
As I'm living in the Netherlands, this is 2 hours earlier than the local time (1 hour plus 1 hour for daylight saving). To compensate this I use the getTimezoneOffset() method. This method, however, returns 0. What do I do wrong here?
function checkTime()
{
var now = new Date();

alert('now.getHours() is ' + now.getHours()
+ '; now.getUTCHours() is ' + now.getUTCHours()
+ '; now.getTimezoneOffset() is '+ now.getTimezoneOffset()
+ '; now.toString() is ' + now.toString()
);

}

Results at 22:13 pm local time:

now.getHours() is 20; now.getUTCHours() is 20; now.getTimezoneOffset() is 0; nowtoString() is Sun, 13 apr, 2013:33

Help!

User avatar
bertkessels
Posts: 15
Joined: 6. Nov 05, 14:05
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Unable to get the local time in a script

Postby bertkessels » 13. Apr 08, 22:09

The problem seems to be related to the windows option for automatic adaption to daylight saving time.
(In the dutch Windows version this is the option: "Klok automatisch aanpassen aan zomertijd en wintertijd", its on the timezone tab of the date/time settings)
I switched the option off and getHours() now returns the local time correctly, getTimeZoneOffset() returns now -60 (minutes) which is correct. Is this a bug in Windows or in Silverjuke?

User avatar
Service-Team
Posts: 2448
Joined: 7. Dec 04, 04:48
Location: Germany
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Unable to get the local time in a script

Postby Service-Team » 14. Apr 08, 10:24

Hello bertkessels,

thank you for your report, we will check this when we update the underlying JavaScript-engine in one of the next Silverjuke updates.

Best regards,
Your Silverjuke-Team

User avatar
bertkessels
Posts: 15
Joined: 6. Nov 05, 14:05
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Unable to get the local time in a script

Postby bertkessels » 14. Apr 08, 21:03

OK. Thanx.
I have a work-around for now, so no hurry.
regards,
Bert

SilverEagle
Posts: 713
Joined: 30. Sep 08, 14:00
Location: Netherlands
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Unable to get the local time in a script

Postby SilverEagle » 16. Apr 09, 15:05

Hi Team,

One year later, 16:01 on the wallclock and in Windows (XP). But Silverjuke still thinks both new Date().getHours() and new Date().getUTCHours() are 14...

How do I get a correct local time with 16 hours? (And no, deactivating automatic summertime in XP is not an option ;-))

SilverEagle
Last edited by SilverEagle on 16. Apr 09, 22:19, edited 1 time in total.

User avatar
Frenchi
Posts: 352
Joined: 6. Apr 08, 17:26
Location: Grenoble / France
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Unable to get the local time in a script

Postby Frenchi » 16. Apr 09, 18:39

;-) "newDate().getHours() + 2" is giving the right time, at least during the summertime :twisted:

SilverEagle
Posts: 713
Joined: 30. Sep 08, 14:00
Location: Netherlands
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Unable to get the local time in a script

Postby SilverEagle » 16. Apr 09, 19:04


SilverEagle
Posts: 713
Joined: 30. Sep 08, 14:00
Location: Netherlands
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Unable to get the local time in a script

Postby SilverEagle » 7. May 09, 09:33

Hi Team,

SilverEagle wrote:
> How do I get a correct local time
> ...

Any input on this issue?

Regards,
SilverEagle

User avatar
Service-Team
Posts: 2448
Joined: 7. Dec 04, 04:48
Location: Germany
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Unable to get the local time in a script

Postby Service-Team » 7. May 09, 12:41

Sorry for some delays, however, we have this point on our todo-list.

Best regards,
Your Silverjuke-Team


[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Return to “Developer Network”