timezone

How to set a time zone (or a Kind) of a DateTime value?

两盒软妹~` 提交于 2019-12-18 12:04:52
问题 I mean to store strict UTC time in a DateTime variable and output it in ISO 8601 format. To do the last I've used .ToString("yyyy-MM-ddTHH:mm:sszzz"), and it has uncovered that the time zone is UTC+01:00. I've tried to use .Kind = DateTimeKind.Utc, but it says the Kind property has no setter. How do I explicitly specify the time is in UTC? How is the Kind property set? 回答1: While the DateTime.Kind property does not have a setter, the static method DateTime.SpecifyKind creates a DateTime

Convert Unix Timestamp to time zone?

南楼画角 提交于 2019-12-18 11:53:36
问题 I have a unix timestamp that is set to +5, but I'd like to convert it to -5, EST Standard time. I would just make the time stamp be generated in that time zone, but I'm grabbing it from another source which is putting it at +5. Current Unmodified Timestamp Being Converted Into A Date <? echo gmdate("F j, Y, g:i a", 1369490592) ?> 回答1: Use DateTime and DateTimeZone: $dt = new DateTime('@1369490592'); $dt->setTimeZone(new DateTimeZone('America/Chicago')); echo $dt->format('F j, Y, g:i a'); 回答2:

Preserve timezone in PostgreSQL timestamptz type

那年仲夏 提交于 2019-12-18 11:48:26
问题 For an ISO8601 compliant datetime 2004-10-19 10:23:54+02 Is it possible to have that value, with +02 offset, reflected in the stored column value and also preserved when it is selected? From my reading of the appropriate section of the docs Postgres' default behavior is to convert to UTC at which point the original offset is lost. This is certainly what I'm seeing. The data is accessed via an ORM that is not able to add any special tz conversion so I really need to simply store the datetime

How can I ignore committing timezone information in my commit?

杀马特。学长 韩版系。学妹 提交于 2019-12-18 11:48:10
问题 Recently, I forked a repository hosted by github, with contributors spreading all over the world, and found out that the each commit log contains committer's timezone information. 2013-11-07 02:31:41 +0545 <-- This committer is living in Nepal. Surely. 2013-11-04 12:58:36 -0600 <-- This committer is living in CST or Ecuador or Chili or ... 2013-10-31 10:36:36 +0700 <-- This committer is living in Indonesia or Thai or Mongolia or Laos or Australia or ... : I know it's possible to hide this by

Why does this rails query behave differently depending on timezone?

南楼画角 提交于 2019-12-18 11:34:04
问题 I have a rails time-based query which has some odd timezone sensitive behaviour, even though as far as I know I'm using UTC. In a nutshell, these queries give different answers: >> Model.find(:all,:conditions=>['created_at<=?',(Time.now-1.hours).gmtime]).length => 279 >> Model.find(:all,:conditions=>['created_at<=?',(Time.now-1.hours)]).length => 280 Where the DB actually does contain one model created in the last hour, and the total number of models is 280. So only the first query is correct

How to Convert TZInfo identifier to Rails TimeZone name/key

早过忘川 提交于 2019-12-18 11:09:56
问题 How do you convert js values received as TZInfo identifiers to Rails TimeZone name/key? FROM: "America/New_York" returned from JavaScript TZinfo detection TO: "Eastern Time (US & Canada)" convention used in Rails TimeZone or another example: "Pacific/Honolulu" => converted to => "Hawaii" Both are available in ActiveSupport::TimeZone < Object mapping but rails uses the key [i.g. "Eastern Time (US & Canada)" ] in drop-downs, validation & storing to Time.use_zone() . Based on what I understand

UTC Offset in PHP

為{幸葍}努か 提交于 2019-12-18 11:07:32
问题 What's the easiest way to get the UTC offset in PHP, relative to the current (system) timezone? 回答1: date('Z'); returns the UTC offset in seconds. 回答2: // will output something like +02:00 or -04:00 echo date('P'); 回答3: timezone_offset_get() $this_tz_str = date_default_timezone_get(); $this_tz = new DateTimeZone($this_tz_str); $now = new DateTime("now", $this_tz); $offset = $this_tz->getOffset($now); Untested, but should work 回答4: I did a slightly modified version of what Oscar did. date

How can I get the timezone name in JavaScript?

大憨熊 提交于 2019-12-18 10:26:18
问题 I know how to get the timezone offset, but what I need is the ability to detect something like "America/New York." Is that even possible from JavaScript or is that something I am going to have to guestimate based on the offset? 回答1: The Internationalization API supports getting the user timezone, and is supported in all current browsers. console.log(Intl.DateTimeFormat().resolvedOptions().timeZone) Keep in mind that on some older browser versions that support the Internationalization API, the

Chrome timeZone option to Date.toLocaleString()

◇◆丶佛笑我妖孽 提交于 2019-12-18 10:20:43
问题 I have recently discovered that there is a new extension to JavaScript. This adds several features to the Date object in the toLocaleString , toLocaleDateString and toLocaleTimeString functions. Reference here. I am particularly interested in the timeZone option, that supports IANA/Olson time zones, such as America/New_York or Europe/London . This is currently only supported in Google Chrome . Previous advice was that to work in JavaScript with any other time zone than UTC or your own local

Using current time in UTC as default value in PostgreSQL

浪尽此生 提交于 2019-12-18 09:57:30
问题 I have a column of the TIMESTAMP WITHOUT TIME ZONE type and would like to have that default to the current time in UTC. Getting the current time in UTC is easy: postgres=# select now() at time zone 'utc'; timezone ---------------------------- 2013-05-17 12:52:51.337466 (1 row) As is using the current timestamp for a column: postgres=# create temporary table test(id int, ts timestamp without time zone default current_timestamp); CREATE TABLE postgres=# insert into test values (1) returning ts;