utc

Does Python's time.time() return a timestamp in UTC? [duplicate]

谁说胖子不能爱 提交于 2019-11-30 05:08:21
This question already has an answer here: Does Python's time.time() return the local or UTC timestamp? 7 answers I need to generate a UNIX timestamp in UTC time so I'm using time.time() to produce it. Do I need to do anything else or is the timestamp automatically in UTC? Technically, time.time() doesn't specify, and practically, at least in CPython, it returns a timestamp in whatever format is used by the underlying standard C library's time function. The C standard (which isn't freely available) doesn't say whether this is GMT, and neither does the POSIX standard . It just says: The time()

GMT、UTC、UNIX时间戳、时区

旧时模样 提交于 2019-11-30 04:06:48
GMT、UTC、CTS: UTC时间:世界协调时间(UTC)是世界上不同国家用来调节时钟和时间的主要时间标准,也就是零时区的时间。UTC是以原子时秒长为基础,在时刻上尽量接近于GMT的一种时间计量系统。为确保UTC与GMT相差不会超过0.9秒,在有需要的情况下会在UTC内加上正或负闰秒。UTC现在作为世界标准时间使用。 GMT:即格林尼治标准时间,也就是世界时。GMT的正午是指当太阳横穿格林尼治子午线(本初子午线)时的时间。但由于地球自转不均匀不规则,导致GMT不精确,现在已经不再作为世界标准时间使用。所以,UTC与GMT基本上等同,误差不超过0.9秒。 CST时间:中央标准时间 Central Standard Time (USA) UT-6:00(美国cst时间:零区时减6个小时) Central Standard Time (Australia) UT+9:30(澳大利亚cst:加9个半小时) China Standard Time UT+8:00(中国cst:加8个小时) Cuba Standard Time UT-4:00 (古巴cst:减4个小时) 如:当UTC时间为0点时,中国CST时间为8点,因为零时区和中国北京时区相差8个时区。 时区: 地球自西向东旋转,东边比西边先看到太阳,东边的时间也比西边的早。为了统一世界的时间

Scheduling & DST

十年热恋 提交于 2019-11-30 03:29:01
问题 I am writing a calendar/scheduling app in PHP. Right now I take the day of the week you want the event to occur on and the time. I also ask for the timezone and adjust accordingly to get the event time in GMT. Then I store that time as an offset from midnight of the day of the show. This is fine and works great, but what happens when I hit daylight savings time? I'm not sure what to do when that happens. The other problem is that not all countries have DST so I'm kind of in a bind there. I am

Getting current GMT time

南笙酒味 提交于 2019-11-30 03:07:23
Is there a method in C# that returns the UTC (GMT) time zone? Not based on the system's time. Basically I want to get the correct UTC time even if my system time is not right. Instead of calling DateTime.Now.ToUniversalTime() you can call DateTime.UtcNow Same thing but shorter :) Documentation here . Not based on the system's time? You'd need to make a call to a network time service or something similar. You could write an NTP client, or just screenscrape World Clock ;) I don't believe .NET has an NTP client built in, but there are quite a few available . Nicki I use this from UNITY //Get a

UTC Offset in PHP

萝らか妹 提交于 2019-11-30 01:20:39
What's the easiest way to get the UTC offset in PHP, relative to the current (system) timezone? date('Z'); returns the UTC offset in seconds. Tuhin Bepari // will output something like +02:00 or -04:00 echo date('P'); 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 I did a slightly modified version of what Oscar did. date_default_timezone_set('America/New_York'); $utc_offset = date('Z') / 3600; This gave me the offset from my timezone

C# DateTime to UTC Time without changing the time

萝らか妹 提交于 2019-11-30 01:05:16
How would I convert a preexisting datetime to UTC time without changing the actual time. Example: DateTime dateTime = GetSomeDateTime(); // dateTime here is 3pm dateTime.ToUtcDateTime() // datetime should still be 3pm 6/1/2011 4:08:40 PM Local 6/1/2011 4:08:40 PM Utc from DateTime dt = DateTime.Now; Console.WriteLine("{0} {1}", dt, dt.Kind); DateTime ut = DateTime.SpecifyKind(dt, DateTimeKind.Utc); Console.WriteLine("{0} {1}", ut, ut.Kind); Use the DateTime.SpecifyKind static method. Creates a new DateTime object that has the same number of ticks as the specified DateTime, but is designated as

JDBC/MySQL: Save timestamp always using UTC

℡╲_俬逩灬. 提交于 2019-11-29 22:11:04
问题 I would like to save a timestamp to the database without being converted to the local timezone by the jdbc driver. Currently only MySQL and PostgreSQL are important for me but i would appreciate if there is a database independent solution. Example: // i want that to be saved as 1970-01-01 00:00:00 TimeStamp ts = new java.sql.Timestamp(0); // gets transformed to local time by jdbc driver (in my case to 1970-01-01 01:00:00) st.setTimestamp(0, new java.sql.Timestamp(0)); // only works using

SQL Server - Convert date field to UTC

扶醉桌前 提交于 2019-11-29 21:15:20
I have recently updated my system to record date/times as UTC as previously they were storing as local time. I now need to convert all the local stored date/times to UTC. I was wondering if there is any built in function, similar to .NET's ConvertTime method? I am trying to avoid having to write a utility app to do this for me. Any suggestions? If they're all local to you, then here's the offset: SELECT GETDATE() AS CurrentTime, GETUTCDATE() AS UTCTime and you should be able to update all the data using: UPDATE SomeTable SET DateTimeStamp = DATEADD(hh, DATEDIFF(hh, GETDATE(), GETUTCDATE()),

Get DateTime as UTC with Dapper

僤鯓⒐⒋嵵緔 提交于 2019-11-29 20:24:00
I'm using Dapper to map my entities to SQL Server CE. If I save a DateTime with Kind=Utc , when I read it back I get a DateTime with Kind=Unspecified , which leads to all kind of problems. Example: var f = new Foo { Id = 42, ModificationDate = DateTime.UtcNow }; Console.WriteLine("{0} ({1})", f.ModificationDate, f.ModificationDate.Kind); connection.Execute("insert into Foo(Id, ModificationDate) values(@Id, @ModificationDate)", f); var f2 = connection.Query<Foo>("select * from Foo where Id = @Id", f).Single(); Console.WriteLine("{0} ({1})", f2.ModificationDate, f2.ModificationDate.Kind); This

MYSQL query / dates older than 1 week ago (all datetimes in UTC)

自闭症网瘾萝莉.ら 提交于 2019-11-29 20:14:16
How do I query a mysql db to return all records with a datetime older than 1 week ago. Note that the datetime table stores everything in UTC, and i should be comparing it in that itself... Jusst to be clear - I'm looking for a pure mysql query SELECT * FROM tbl WHERE datetime < NOW() - INTERVAL 1 WEEK If your table stores datetimes in different timezone than what NOW() returns, you can use UTC_TIMESTAMP() instead to get the timestamp in UTC. SELECT * FROM table WHERE DATEDIFF(NOW(),colname) > 7; Michael Pakhantsov SELECT SUBDATE('2008-01-02', 7); OR SELECT SUBDATE(now(), INTERVAL 1 week);