utc

C code to get local time offset in minutes relative to UTC?

六月ゝ 毕业季﹏ 提交于 2019-12-18 05:49:27
问题 I didn't find a trivial way to get the time offset in minutes between the local time and the UTC time. At first I intended to use tzset() but it doesn't provide the daylight saving time. According to the man page, it is simply an integer different of zero if day light saving is in effect. While it is usually an hour, it may be half an hour in some country. I would prefer avoiding to compute the time difference between current UTC returned by gmtime() and localtime() . A more general solution

timezone with DST handling by PHP

寵の児 提交于 2019-12-17 23:38:39
问题 I am working on a calendar application. In this users from different time-zones create/view events. I am thinking to follow below method to save event time in UTC and display them in user's local time. Note: user has their preferred timezone setting. To save event start time as UTC timestamp: $timezone = new DateTimeZone( $user_timezone_name ); $utcOffset = $timezone->getOffset( new DateTime( $event_start_time_string_local ) ); $event_start_timestamp_local = maketime( $event_start_time_string

How to show a UTC time as local time in a webpage?

给你一囗甜甜゛ 提交于 2019-12-17 22:40:16
问题 I have a database that holds a time as UTC. This time can be shown in a webpage, so I’ve been asked to show it as local time in the page as it can be viewed from any country. A colleague mentioned something about getting the country settings from the current thread (on the server) but I couldn’t find any details on this. Is what I want to do possible? 回答1: If you (and your website) are comfortable with javascript, there is a very easy way to accomplish this. First, on the server side, you

How do I make MySQL's NOW() and CURDATE() functions use UTC?

无人久伴 提交于 2019-12-17 18:13:09
问题 I want to make it so calls to NOW() and CURDATE() in MySQL queries return the date in UTC. How do I make this happen without going through and changing all queries that use these functions? 回答1: Finally found what I was looking for... In my.cnf, [mysqld_safe] timezone = UTC I was putting this option under [mysqld], and mysql was failing to start. Calling "SET time_zone='+0:00';" on every page load would also work, but I don't like the idea of calling that query on every single page load. 回答2:

pytz utc conversion

你说的曾经没有我的故事 提交于 2019-12-17 17:33:27
问题 What is the right way to convert a naive time and a tzinfo into an UTC time? Say I have: d = datetime(2009, 8, 31, 22, 30, 30) tz = timezone('US/Pacific') First way, pytz inspired: d_tz = tz.normalize(tz.localize(d)) utc = pytz.timezone('UTC') d_utc = d_tz.astimezone(utc) Second way, from UTCDateTimeField def utc_from_localtime(dt, tz): dt = dt.replace(tzinfo=tz) _dt = tz.normalize(dt) if dt.tzinfo != _dt.tzinfo: # Houston, we have a problem... # find out which one has a dst offset if _dt

Get DateTime as UTC with Dapper

北战南征 提交于 2019-12-17 17:32:43
问题 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 =

How to convert from UTC to local time in C?

与世无争的帅哥 提交于 2019-12-17 16:13:28
问题 It's a simple question, but the solution appears to be far from simple. I would like to know how to convert from UTC to local time. I am looking for a solution in C that's standard and more or less guaranteed to work on any computer at any location. I have read the following links carefully but I can't find a solution there: Converting string containing localtime into UTC in C Converting Between Local Times and GMT/UTC in C/C++ I have tried a number of variations, such as (datetime is a

get UTC timestamp in python with datetime

依然范特西╮ 提交于 2019-12-17 15:21:16
问题 Is there a way to get the UTC timestamp by specifying the date? What I would expect: datetime(2008, 1, 1, 0, 0, 0, 0) should result in 1199145600 Creating a naive datetime object means that there is no time zone information. If I look at the documentation for datetime.utcfromtimestamp, creating a UTC timestamp means leaving out the time zone information. So I would guess, that creating a naive datetime object (like I did) would result in a UTC timestamp. However: then = datetime(2008, 1, 1, 0

DateTime.Parse(“2012-09-30T23:00:00.0000000Z”) always converts to DateTimeKind.Local

折月煮酒 提交于 2019-12-17 10:32:32
问题 I want to parse a string that represent a DateTime in UTC format. My string representation includes the Zulu time specification which should indicate that the string represent a UTC time. var myDate = DateTime.Parse("2012-09-30T23:00:00.0000000Z"); From the above I would expect myDate.Kind to be DateTimeKind.Utc, instead it is DatetimeKind.Local. What am I doing wrong and how to Parse a string that represents a UTC time? Many thanks! 回答1: I would use my Noda Time project personally.

Android get Current UTC time [duplicate]

試著忘記壹切 提交于 2019-12-17 07:11:11
问题 This question already has answers here : How can I get the current date and time in UTC or GMT in Java? (31 answers) Closed 6 years ago . What is the function to get the current UTC time. I have tried with System.getCurrentTime but i get the current date and time of the device. Thanks 回答1: System.currentTimeMillis() does give you the number of milliseconds since January 1, 1970 00:00:00 UTC. The reason you see local times might be because you convert a Date instance to a string before using