Hello everyone.
I am creating a JavaScript project which will allow users to see what
time it is in other countries. I am wondering if there's any way to
have the server work this out, without having to update a database
constantly with the times and dates that certain countries set their
clocks back or forward.
Can this be done, or do I need to connect to a time server? Ideally, I
need a time server that will return a JavaScript object containing the
information I need, but I don't think one exists.
Please could someone suggest the steps I need to take to quickly
obtain the correct time for any given country, which will take DST
into account? Sadly, to my knowledge, the UK is the only country that
has hard-coded rules for when the clocks are changed, where as it
seems to be a political thing for all other countries.
If I have to run a database with this information, then so be it, but
it seems like a lot of manual work, and I'm not sure how often I'd
need to update it.
Many thanks in advance.
Daz. 3 3064
On 27 May 2007 06:24:49 -0700, Daz <cu********@gmail.comwrote:
>I am creating a JavaScript project which will allow users to see what time it is in other countries. I am wondering if there's any way to have the server work this out, without having to update a database constantly with the times and dates that certain countries set their clocks back or forward.
Can this be done, or do I need to connect to a time server? Ideally, I need a time server that will return a JavaScript object containing the information I need, but I don't think one exists.
Please could someone suggest the steps I need to take to quickly obtain the correct time for any given country, which will take DST into account? Sadly, to my knowledge, the UK is the only country that has hard-coded rules for when the clocks are changed, where as it seems to be a political thing for all other countries.
If I have to run a database with this information, then so be it, but it seems like a lot of manual work, and I'm not sure how often I'd need to update it.
Most operating systems have comprehensive timezone data available, which gets
taken into account via the TZ environment variable when formatting UNIX
timestamps (which are always based on UTC).
PHP 5.1 introduced improved timezone handling into the core of PHP itself,
see: http://uk2.php.net/manual/en/functio...mezone-set.php (which
is preferred over setting environment variables, if available).
<?php
foreach (array('US/Eastern', 'US/Central', 'UTC', 'Europe/London',
'Europe/Paris') as $tz)
{
putenv("TZ=$tz"); // or use date_default_timezone_set
print date("r") . " (TZ=$tz)\n";
}
?>
$ php test.php
Sun, 27 May 2007 09:56:21 -0400 (TZ=US/Eastern)
Sun, 27 May 2007 08:56:21 -0500 (TZ=US/Central)
Sun, 27 May 2007 14:56:21 +0100 (TZ=Europe/London)
Sun, 27 May 2007 15:56:21 +0200 (TZ=Europe/Paris)
Sun, 27 May 2007 13:56:21 +0000 (TZ=UTC)
--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
On May 27, 2:58 pm, Andy Hassall <a...@andyh.co.ukwrote:
On 27 May 2007 06:24:49 -0700, Daz <cutenfu...@gmail.comwrote:
I am creating a JavaScript project which will allow users to see what
time it is in other countries. I am wondering if there's any way to
have the server work this out, without having to update a database
constantly with the times and dates that certain countries set their
clocks back or forward.
Can this be done, or do I need to connect to a time server? Ideally, I
need a time server that will return a JavaScript object containing the
information I need, but I don't think one exists.
Please could someone suggest the steps I need to take to quickly
obtain the correct time for any given country, which will take DST
into account? Sadly, to my knowledge, the UK is the only country that
has hard-coded rules for when the clocks are changed, where as it
seems to be a political thing for all other countries.
If I have to run a database with this information, then so be it, but
it seems like a lot of manual work, and I'm not sure how often I'd
need to update it.
Most operating systems have comprehensive timezone data available, which gets
taken into account via the TZ environment variable when formatting UNIX
timestamps (which are always based on UTC).
PHP 5.1 introduced improved timezone handling into the core of PHP itself,
see:http://uk2.php.net/manual/en/functio...-set.php(which
is preferred over setting environment variables, if available).
<?php
foreach (array('US/Eastern', 'US/Central', 'UTC', 'Europe/London',
'Europe/Paris') as $tz)
{
putenv("TZ=$tz"); // or use date_default_timezone_set
print date("r") . " (TZ=$tz)\n";}
?>
$ php test.php
Sun, 27 May 2007 09:56:21 -0400 (TZ=US/Eastern)
Sun, 27 May 2007 08:56:21 -0500 (TZ=US/Central)
Sun, 27 May 2007 14:56:21 +0100 (TZ=Europe/London)
Sun, 27 May 2007 15:56:21 +0200 (TZ=Europe/Paris)
Sun, 27 May 2007 13:56:21 +0000 (TZ=UTC)
--
Andy Hassall :: a...@andyh.co.uk ::http://www.andyh.co.ukhttp://www.and....co.uk/space:: disk and FTP usage analysis tool
Hi Andy. That's wonderful. Thank you very much for such a great
example. Sadly, the server I am doing this project for, is running PHP
4...
Am I correct in saying that DST has been accounted for in your
example? It looks like it has, but I need to be certain.
Thanks again.
Daz.
On 27 May 2007 07:15:14 -0700, Daz <cu********@gmail.comwrote:
>Hi Andy. That's wonderful. Thank you very much for such a great example. Sadly, the server I am doing this project for, is running PHP 4...
Not so bad, since the TZ environment variable will still work. From another
server:
$ php -v
PHP 4.3.10 (cli) (built: Jan 12 2005 13:10:04)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies
$ php test.php
Sun, 27 May 2007 14:34:24 +0000 (TZ=US/Eastern)
Sun, 27 May 2007 14:34:24 +0000 (TZ=US/Central)
Sun, 27 May 2007 14:34:24 +0000 (TZ=UTC)
Sun, 27 May 2007 15:34:24 +0100 (TZ=Europe/London)
Sun, 27 May 2007 16:34:24 +0200 (TZ=Europe/Paris)
OK, that server won't take US/Eastern or Central - they're wrongly coming out
as +0000. It apparently takes the city-based US timezones, though:
Sun, 27 May 2007 10:39:44 -0400 (TZ=America/New_York)
Sun, 27 May 2007 09:39:44 -0500 (TZ=America/Chicago)
Sun, 27 May 2007 14:39:44 +0000 (TZ=UTC)
Sun, 27 May 2007 15:39:44 +0100 (TZ=Europe/London)
Sun, 27 May 2007 16:39:44 +0200 (TZ=Europe/Paris)
The supported timezone names in PHP 4 rely entirely on the operating system -
in this case it seems FreeBSD's timezones list differs slightly from Linux.
PHP 5's improved support is useful as it has its own timezone database, so
it's more portable.
>Am I correct in saying that DST has been accounted for in your example? It looks like it has, but I need to be certain.
Yes, it has. See "Europe/London" being +1 as we're in British Summer Time at
the moment.
--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: B. G. Mahesh |
last post by:
hi
I am using PHP 4.x and MySQL. The database has the list of countries,
cities and timezones.
I would like to convert the time from one zone to another zone .
It is not that difficult to...
|
by: Michael |
last post by:
I would like to set the timezone of a thread to allow me
to calculate the UTC time for data sourced from a number
of time zones. Although this can be done in C and C++, I
annot find how to do...
|
by: Robert Treat |
last post by:
I am trying to figure out if there is a way to determine the timezones
supported in postgresql from within the database. If you look at...
|
by: Flack |
last post by:
Hey guys,
I need to compare two times that the user selects. The user selects the
hour, date, and timezone (which can be either NY, LN, or HK timezones).
How can I compare two dates of...
|
by: Alex |
last post by:
Hi
My website is hosted in the States (EST), but the website itself is
targeted for UK users (GMT).
How can I offset the time so that the server reports it as GMT when my
ASP.NET app needs to...
|
by: =?Utf-8?B?U3R1?= |
last post by:
I have a ASP.NET Ajax app (using client library) calling ASP.NET Ajax-enabled
web services. We are making use of the javascript proxies generated by
ASP.NET Ajax.
The problem we have is that the...
|
by: Daz |
last post by:
Hello everyone.
I am creating a JavaScript project which will allow users to see what
time it is in other countries. I am wondering if there's any way to
have the server work this out, without...
|
by: David T. Ashley |
last post by:
In a web database (PHP), per user, I'd like to allow each user to specify
their timezone (this would change how times are adjusted for display for
that user).
How do I enumerate all possible...
|
by: Sanjay |
last post by:
Hi All,
I am using pytz.common_timezones to populate the timezone combo box of
some user registration form. But as it has so many timezones (around
400), it is a bit confusing to the users. Is...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |