LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-07-2010, 07:51 AM   #1
neioo
LQ Newbie
 
Registered: Jan 2008
Location: Sant Quinti de Mediona
Distribution: Gentoo
Posts: 25

Rep: Reputation: 3
Handling time zone [SOLVED]


Hi there,

I'm developing my web site and I was looking for the best way to handle time zones and its conversions. After two weeks looking and trying different alternatives, I got the good way, so I want share the problems I found and how I solved it.

Some points:
  1. Users around the world can access to your web site, the time is not the same for them all.
  2. Timezone conversion is not a trivial issue i.e. daylight saving time.

One of the first point I noticed, is that the best way is save all dates in the same time zone: I decided UTC. In that way I can sort all items of my website by date easily.

Next the question was how to translate all dates to the user date, at first I thought to make an script with javascript that tells me which time zone offset the user is using, but there is a problem: because winter dates (can) use a different time zone offset from summer time zone dates (you cannot apply same time zone offset).

So, javascript is out. Next, I thought to use php (or your favourite language to program your 2.0 website), to make the translation. The first point, is that you must ask to the user which time zone name is using. And then you store its time zone name into you database, and when presenting some dates to the user make its conversion. Here, there is no problem because the conversion date API are acceptable. But the point is that if you manage all dates directly from your SQL server things get better.

So, you ask to the user which time zone name is using and store it into your database. Next, when you select a date, you can use SQL to convert it to the user's time zone (in Postgresql):
Quote:
SELECT current_time AT TIME ZONE 'Europe/Madrid';
And this simple solution is what I was looking during two weeks U_U, I hope it will be useful to someone.
 
Old 12-07-2010, 08:15 AM   #2
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Thank you. That is a tricky issue.
 
Old 12-09-2010, 03:07 PM   #3
resetreset
Senior Member
 
Registered: Mar 2008
Location: Cyberspace
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,340

Rep: Reputation: 62
Yeah, thanks neioo. Do you have any idea what would be done in MySQL though?
 
Old 12-10-2010, 08:10 AM   #4
neioo
LQ Newbie
 
Registered: Jan 2008
Location: Sant Quinti de Mediona
Distribution: Gentoo
Posts: 25

Original Poster
Rep: Reputation: 3
Quote:
Originally Posted by resetreset View Post
Yeah, thanks neioo. Do you have any idea what would be done in MySQL though?
A fast Google search took me to: http://www.techiegyan.com/2009/11/05...vert_tz-mysql/

But since Oracle bought Sun, I don't use MySQL any more.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting time and time zone altogether properly in Slack-current, KDE4 spaceballs Slackware 3 04-20-2011 05:15 AM
Run script in EST time zone but server is in GMT zone jeesun Linux - Networking 1 04-04-2010 01:37 PM
Time zone sets inappropriate time during Ubuntu 9.04 installation TristanDee Ubuntu 6 07-24-2009 06:42 AM
Time skew of 580 min when I set my time zone in Gentoo scooter2 Linux - Newbie 1 03-05-2009 10:27 AM
Cannot set time/date to other time zone than UTC (Kubuntu) jamangold Ubuntu 1 12-23-2005 05:42 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration