Обсуждение: Time AT TIME ZONE: false result using offset instead of time zone name
Hi, I am living in the Central European Time (CET == GMT+1) SELECT CURRENT_TIMESTAMP ; now timestamp with time zone ---------------------------- 2014-02-11 08:21:52.83588+01 And I want this without time zone but also for my own time zone (checking AT TIME ZONE); sure, I get it correct... the same... SELECT CURRENT_TIMESTAMP AT TIME ZONE 'CET'; timezone timestamp without time zone ---------------------------- 2014-02-11 08:22:39.586382 But it would be easier to ask a specific time offset (got from a client around the world), so for me +01 hour: SELECT CURRENT_TIMESTAMP AT TIME ZONE 'UTC+01'; timezone timestamp without time zone --------------------------- 2014-02-11 06:23:07.043479 !!! Two hours earlyer, one hour to the east (Azores), not to the west of Greenwich. To get my time one hour west from Greenwich I have to ask: SELECT CURRENT_TIMESTAMP AT TIME ZONE 'UTC-01'; Is this inverse calculation intently? Thank you! Regards, Rawi -- View this message in context: http://postgresql.1045698.n5.nabble.com/Time-AT-TIME-ZONE-false-result-using-offset-instead-of-time-zone-name-tp5791371.html Sent from the PostgreSQL - sql mailing list archive at Nabble.com.
On 02/10/2014 11:54 PM, rawi wrote: > Hi, > I am living in the Central European Time (CET == GMT+1) > > SELECT CURRENT_TIMESTAMP ; > > now > timestamp with time zone > ---------------------------- > 2014-02-11 08:21:52.83588+01 > > And I want this without time zone but also for my own time zone (checking AT > TIME ZONE); sure, I get it correct... the same... > > SELECT CURRENT_TIMESTAMP AT TIME ZONE 'CET'; > > timezone > timestamp without time zone > ---------------------------- > 2014-02-11 08:22:39.586382 > > But it would be easier to ask a specific time offset (got from a client > around the world), so for me +01 hour: > > SELECT CURRENT_TIMESTAMP AT TIME ZONE 'UTC+01'; > > timezone > timestamp without time zone > --------------------------- > 2014-02-11 06:23:07.043479 > > !!! Two hours earlyer, one hour to the east (Azores), not to the west of > Greenwich. > To get my time one hour west from Greenwich I have to ask: > > SELECT CURRENT_TIMESTAMP AT TIME ZONE 'UTC-01'; > > Is this inverse calculation intently? Yes. http://www.postgresql.org/docs/9.3/interactive/datatype-datetime.html#DATATYPE-TIMEZONES 8.5.3. Time Zones .. Another issue to keep in mind is that in POSIX time zone names, positive offsets are used for locations west of Greenwich. Everywhere else, PostgreSQL follows the ISO-8601 convention that positive timezone offsets are east of Greenwich > > Thank you! > Regards, Rawi > > > > > -- > View this message in context: http://postgresql.1045698.n5.nabble.com/Time-AT-TIME-ZONE-false-result-using-offset-instead-of-time-zone-name-tp5791371.html > Sent from the PostgreSQL - sql mailing list archive at Nabble.com. > > -- Adrian Klaver adrian.klaver@gmail.com
Adrian Klaver-3 wrote >>On 02/10/2014 11:54 PM, rawi wrote: >>[...] >> SELECT CURRENT_TIMESTAMP AT TIME ZONE 'UTC+01'; >> >> timezone >> timestamp without time zone >> --------------------------- >> 2014-02-11 06:23:07.043479 >> >> !!! Two hours earlyer, one hour to the east (Azores), not to the west of >> Greenwich. >> To get my time one hour west from Greenwich I have to ask: >> >> SELECT CURRENT_TIMESTAMP AT TIME ZONE 'UTC-01'; >> >> Is this inverse calculation intently? > > Yes. > > http://www.postgresql.org/docs/9.3/interactive/datatype-datetime.html#DATATYPE-TIMEZONES > > 8.5.3. Time Zones > > .. Another issue to keep in mind is that in POSIX time zone names, > positive offsets are used for locations west of Greenwich. Everywhere > else, PostgreSQL follows the ISO-8601 convention that positive timezone > offsets are east of Greenwich Oh... oh... Disconcerting... I've just learned, that even javascript is returning negative offsets for western situated browsers... Thank you! Regards, Rawi -- View this message in context: http://postgresql.1045698.n5.nabble.com/Time-AT-TIME-ZONE-false-result-using-offset-instead-of-time-zone-name-tp5791371p5791556.html Sent from the PostgreSQL - sql mailing list archive at Nabble.com.
Re: Re: Time AT TIME ZONE: false result using offset instead of time zone name
От
Adrian Klaver
Дата:
On 02/12/2014 12:24 AM, rawi wrote: > Adrian Klaver-3 wrote >>> On 02/10/2014 11:54 PM, rawi wrote: >>> [...] >>> SELECT CURRENT_TIMESTAMP AT TIME ZONE 'UTC+01'; >>> >>> timezone >>> timestamp without time zone >>> --------------------------- >>> 2014-02-11 06:23:07.043479 >>> >>> !!! Two hours earlyer, one hour to the east (Azores), not to the west of >>> Greenwich. >>> To get my time one hour west from Greenwich I have to ask: >>> >>> SELECT CURRENT_TIMESTAMP AT TIME ZONE 'UTC-01'; >>> >>> Is this inverse calculation intently? >> >> Yes. >> >> http://www.postgresql.org/docs/9.3/interactive/datatype-datetime.html#DATATYPE-TIMEZONES >> >> 8.5.3. Time Zones >> >> .. Another issue to keep in mind is that in POSIX time zone names, >> positive offsets are used for locations west of Greenwich. Everywhere >> else, PostgreSQL follows the ISO-8601 convention that positive timezone >> offsets are east of Greenwich > > Oh... oh... Disconcerting... I've just learned, that even javascript is > returning negative offsets for western situated browsers... Welcome to the wacky world of time, it is all relative:) The choices are handle everything as UTC until you present to the end user or use actual timezones, for example, America/Los_Angeles. To illustrate, in your original post you said: "But it would be easier to ask a specific time offset (got from a client around the world), so for me +01 hour" Do you know if that offset supplied by the client was POSIX or ISO in its sign? > > Thank you! > Regards, Rawi > > > -- Adrian Klaver adrian.klaver@gmail.com
Adrian Klaver-3 wrote > Welcome to the wacky world of time, it is all relative:) The choices are > handle everything as UTC until you present to the end user or use actual > timezones, for example, America/Los_Angeles. To illustrate, in your > original post you said: > > "But it would be easier to ask a specific time offset (got from a client > around the world), so for me +01 hour" > > Do you know if that offset supplied by the client was POSIX or ISO in > its sign? The (playing) question was: how would I get the time zone of a browser somewhere unknown on earth? And the found javascript solution would return the difference between GMT and localtime in minutes, so for me west from Greenwich a negative integer. Please save the following in a html file eg. "time_offset.html" and load it in your browser: -- View this message in context: http://postgresql.1045698.n5.nabble.com/Time-AT-TIME-ZONE-false-result-using-offset-instead-of-time-zone-name-tp5791371p5791602.html Sent from the PostgreSQL - sql mailing list archive at Nabble.com.
Re: Re: Time AT TIME ZONE: false result using offset instead of time zone name
От
Adrian Klaver
Дата:
On 02/12/2014 07:29 AM, rawi wrote: > Adrian Klaver-3 wrote >> Welcome to the wacky world of time, it is all relative:) The choices are >> handle everything as UTC until you present to the end user or use actual >> timezones, for example, America/Los_Angeles. To illustrate, in your >> original post you said: >> >> "But it would be easier to ask a specific time offset (got from a client >> around the world), so for me +01 hour" >> >> Do you know if that offset supplied by the client was POSIX or ISO in >> its sign? > > The (playing) question was: how would I get the time zone of a browser > somewhere unknown on earth? > > And the found javascript solution would return the difference between GMT > and localtime in minutes, so for me west from Greenwich a negative integer. > > Please save the following in a html file eg. "time_offset.html" and load it > in your browser: I do not see the code, so I can not test. > > > > > -- Adrian Klaver adrian.klaver@gmail.com
Re: Re: Time AT TIME ZONE: false result using offset instead of time zone name
От
Adrian Klaver
Дата:
On 02/12/2014 07:29 AM, rawi wrote: > Adrian Klaver-3 wrote >> Welcome to the wacky world of time, it is all relative:) The choices are >> handle everything as UTC until you present to the end user or use actual >> timezones, for example, America/Los_Angeles. To illustrate, in your >> original post you said: >> >> "But it would be easier to ask a specific time offset (got from a client >> around the world), so for me +01 hour" >> >> Do you know if that offset supplied by the client was POSIX or ISO in >> its sign? > > The (playing) question was: how would I get the time zone of a browser > somewhere unknown on earth? > > And the found javascript solution would return the difference between GMT > and localtime in minutes, so for me west from Greenwich a negative integer. > > Please save the following in a html file eg. "time_offset.html" and load it > in your browser: I am on the US Pacific Coast so my current timezone is PST, UTC-8 ISO So using javascript in my browser: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset var offset = new Date().getTimezoneOffset(); offset = 480 480 minutes/60 minutes = 8 hours Which tracks with the above link: "The time-zone offset is the difference, in minutes, between UTC and local time. Note that this means that the offset is positive if the local timezone is behind UTC and negative if it is ahead." and also the POSIX offset. You just have to remember to invert sign for your local timezone when doing the AT TIMEZONE if you use the POSIX method. Of course you are counting on the client having their environment set up correctly. > > > > > -- Adrian Klaver adrian.klaver@gmail.com