utc

How do I convert local time to UTC in Python?

How do I convert a datetime string in local time to a string in UTC time? I'm sure I've done this before, but can't find it and SO will hopefully help me (and others) do that in future. Clarification: For example, if I have "2008-09-17 14:02:00" in my local timezone (+10), I'd like to generate a string with the equivalent UTC time: "2...

C# - Convert UTC/GMT time to local time

We are developing a C# application for a web-service client. This will run on Windows XP PC's. One of the fields returned by the web service is a DateTime field. The server returns a field in GMT format i.e. with a "Z" at the end. However, we found that .NET seems to do some kind of implicit conversion and the time was always 12 hours ...

UTC Offset in PHP

What's the easiest way to get the UTC offset in PHP, relative to the current (system) timezone? ...

Displaying time and timezone information to the user (what, not how)

(This is a question about the UI rather than the technology required to do it) What is the clearest way to display a time for events occurring in different timezones to a user? Does your "average" user understand UTC and timezones? We capture the local time and UTC offset and store it in the database (SQL 2008 DateTimeOffset) for event...

How do I get the UTC time of "midnight" for a given timezone?

The best I can come up with for now is this monstrosity: >>> datetime.utcnow() \ ... .replace(tzinfo=pytz.UTC) \ ... .astimezone(pytz.timezone("Australia/Melbourne")) \ ... .replace(hour=0,minute=0,second=0,microsecond=0) \ ... .astimezone(pytz.UTC) \ ... .replace(tzinfo=None) datetime.datetime(2008, 12, 16, 13, 0) I.e., in ...

Testing correct timezone handling

We are working with large amounts of data, all tagged in UTC (in Java). Between reading this data, storing it in a database and getting it out again, it happened, that some data was off one hour during daylight saving time. As UTC has no concept of daylight saving time this was clearly a bug within the software. Once known, it's easy to ...

How can I convert a date value in UTC format to a date object in Javascript?

I've been trying to convert a UTC value in a string into a more readable format. To do that, I'm trying to parse the date using the Javascript Date.parse method. That however does not work on the input (eg:"2007-09-21T14:15:34.058-07:00") that i have. The end goal is to output a date string like "January 30th, 2008 @ 2:15PM". Any ideas?...

What is the common practice with regards to differentiating between UTC and GMT?

I finally found out the difference between UTC and GMT by making the effort to look it up on Wikipedia today. Technically speaking it appears that GMT != UTC because you do not know if it is UTC or UT1 being referred to. However practically, people use the terms interchangeably to indicate the same timezone. A while ago, I suggested tha...

Scheduling & DST

I am writing a calendar/scheduling app in php right now. 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 ha...

Get UTC date out of SQL Server & show in grid as local time

I've got a table in SQL Server 2005 that has a datetime column holding dates in UTC form. I want clients to call the a .NET server app and the server will return a DataTable with records to be bound client side to a DataGridView. ** On the client the dates should be displayed in local time **, clients will be in may regions of the world....

why is LINQ to SQL tricked by an extension method? what now?

Consider my Event class, and that i store DateTime's in the DB as UTC dates. I simply want to return a filtered range based on the current date in a particular time zone - easy right? This works fine: IQueryable<Event> test1 = this.GetSortedEvents().Where(e => e.FinishDateTime.Date >= DateTime.UtcNow.Date); This also works fine: IQ...

Timestamp as UTC Integer

HI I Have a legacy database with a field containing an integer representing a datetime in UTC From the documentation: "Timestamps within a CDR appear in Universal Coordinated Time (UTC). This value remains independent of daylight saving time changes" An example of a value is 1236772829. My question is what is the best way to convert...

Using TimeZones on website using ASP.Net 3.5 / SQL Server 2005

I am trying to determine, how I should implement local time in a web-app. All users are logged in, there are no anonymous users. They will need to see all time-values in their local time. Is this how it should be done? All DateTime values are saved as UTC-time in database Each user has a UTC-Offset value stored in his profile When dis...

How can I format date -u so that the results include timezone offset in a Mac OSX terminal session?

In a terminal session I can use date -u to get Mon Mar 16 03:34:39 2009 UTC However, I'd like to include the offset. I'm modifying a TextMate tab trigger so that I can insert the full date including the local offset, in standard UTC format. I believe that would be in the following form: Mon Mar 16 03:34:39 2009 UTC -0500 So, as you c...

Grouping Long UTC dates by Day.

Is there a sensible way to group Long UTC dates by Day? I would Mod them by 86400 but that doesn't take leap seconds into account. Does anyone have any other ideas, I'm using java so I could parse them into Date Objects, but I'm a little worried of the performance overhead of using the date class. Also is there a more efficient way th...

.NET 2.0 DateTime UTC conversion

Why does the ToUniversalTime function have no effect here; DateTime dt = new DateTime(2009,3,24,1,0,0,DateTimeKind.Local); dt = dt.ToUniversalTime(); // convert BST to UTC ? dt.ToString(); "24/03/2009 01:00:00" ... wrong? Is the same as.. DateTime dt = new DateTime(2009,3,24,1,0,0,DateTimeKind.Utc); dt = dt.ToUniversalTime(); // not...

Is it possible to get a timezone in python given a utc timestamp and a utc offset?

I have data that is the utc offset and the utc time, given that is it possible to get the users local timezone (mainly to figure if it is dst etc. probably using pytz), similar to the function in php timezone_name_from_abbr ? For example: If my epoch time is: 1238720309 I can get the utc time as: d = datetime.utcfromtim...

Where's the DateTime 'Z' format specifier?

[Update: Format specifiers are not the same thing as format strings; a format specifier is a piece of a custom format string, where a format string is 'stock' and doesn't provide customization. My problem is with specifiers not formats] I've been trying to perform roundtrip DateTime conversions with a format string that uses 'zzz' forma...

.NET 2.0 DateTime.ToString() conversion to different time zone

is there a format in ToString() method of DateTime to convert the time Zone to say UTC ? I know I can programatically first convert the DateTime to UTC and then call ToString, but I have a UI where the user can specify format, can they at the same time convert to UTC ? ...

Determine user agent timezone offset without using javascript?

Is there a way to determine the timezone for a user agent without javasript? normally, i would execute this snippet of javascript: <script type="text/javascript" language="JavaScript"> var offset = new Date(); document.write('<input type="hidden" id="clientTzOffset" name="clientTzOffset" value="' + offset.getTimezoneOffset() + '"/>...