datetimeoffset

Best practices with saving datetime & timezone info in database when data is dependant on datetime

我怕爱的太早我们不能终老 提交于 2019-11-27 17:21:15
There were quite a few questions about saving datetime & timezones info in DB but more on the overall level. Here I'd like to address a specific case. System specs We have an Orders system database It is a multi-tenant system where tenants can use arbitrary timezone (it is arbitrary but single timezone per tenant, saved in Tenants table once and never changes) Business rule needed to be covered in DB When tenant places an Order into the system, order number gets computed based on their local datetime (its not literally a number but some kind of an identifier like ORDR-13432-Year-Month-Day ).

Storing DateTime (UTC) vs. storing DateTimeOffset

守給你的承諾、 提交于 2019-11-27 16:53:31
I usually have an "interceptor" that right before reading/writing from/to the database does DateTime conversion (from UTC to local time, and from local time to UTC), so I can use DateTime.Now (derivations and comparisions) throughout the system without worrying about time zones. Regarding serialization and moving data between computers, there is no need to bother, as the datetime is always UTC. Should I continue storing my dates (SQL 2008 - datetime) in UTC format or should I instead store it using DateTimeOffset (SQL 2008 - datetimeoffset)? UTC Dates in the database (datetime type) have been

Determine Whether Daylight Savings Time (DST) is Active in Java for a Specified Date

偶尔善良 提交于 2019-11-27 12:17:06
I have a Java class that takes in the latitude/longitude of a location and returns the GMT offset when daylight savings time is on and off. I am looking for an easy way to determine in Java if the current date is in daylight savings time so I can apply the correct offset. Currently I am only performing this calculation for U.S. timezones although eventually I would like to expand this to global timezones as well. Clint This is the answer for the machine on which the question is being asked: TimeZone.getDefault().inDaylightTime( new Date() ); A server trying to figure this out for a client will

How does DateTimeOffset deal with daylight saving time?

大憨熊 提交于 2019-11-27 11:57:01
I know that DateTimeOffset stores a UTC date/time and an offset. I also know from this MSDN blog entry that DateTimeOffset should be used to "Work with daylight saving times". What I'm struggling to understand is exactly how DateTimeOffset "work(s) with daylight saving times". My understanding, little that there is, is that daylight saving times are a political decision and cannot be inferred from purely an offset. How can it be that this structure is DST friendly if it only stores an offset? I gather there may be a way to use the TimeZoneInfo class in conjunction with DateTimeOffset. How

When Would You Prefer DateTime Over DateTimeOffset

孤人 提交于 2019-11-27 11:53:24
A few months ago I was introduced to the new DateTimeOffset type and was glad DateTime 's flaws with regard to time zones were finally taken care of. However, I was left wondering if there were any overhead or problems that could occur from using this new type. I work on a multi-locale web application. Does anyone know of anything that could sway me from just using it for all my date/time work? Is there a window for abuse here? Reference: DateTimeOffset: A New DateTime Structure in .NET 3.5 by Justin Van Patten Jon Skeet Sometimes you really just want to represent a "local" (timezone unaware)

How to use TimeZoneInfo to get local time during Daylight Savings Time?

风格不统一 提交于 2019-11-27 06:20:18
I'm trying to use DateTimeOffset to convey a specific moment in time across any time zone. I can't figure out how to use TimeZoneInfo to deal with daylight savings time. var dt = DateTime.UtcNow; Console.WriteLine(dt.ToLocalTime()); var tz = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"); var utcOffset = new DateTimeOffset(dt, TimeSpan.Zero); Console.WriteLine(utcOffset.ToOffset(tz.BaseUtcOffset)); This prints out: 6/2/2010 4:37:19 PM 6/2/2010 3:37:19 PM -06:00 I am in the central time zone, and and we are currently in daylight savings time. I am trying to get the second line to

Does Java 8's new Java Date Time API take care of DST?

独自空忆成欢 提交于 2019-11-27 01:34:04
问题 I am thinking of using the new java 8 Date Time API . I googled a bit and found jodaTime as good choice for java but still kind of interested to see how this new API works. I am storing all time in UTC values in my datastore and will be converting them to Local Time Zone specific value based on user's timezone. I can find many articles showing how to use new Java Date Time API. However I am not sure if the API will take care of DST changes ? Or do we have any better way of handling Date ? I

Subtract 1 day with PHP

南楼画角 提交于 2019-11-26 22:05:30
I'm trying to take a date object that's coming out of my Drupal CMS, subtract one day and print out both dates. Here's what I have $date_raw = $messagenode->field_message_date[0]['value']; print($date_raw); //this gives me the following string: 2011-04-24T00:00:00 $date_object = date_create($date_raw); $next_date_object = date_modify($date_object,'-1 day'); print('First Date ' . date_format($date_object,'Y-m-d')); //this gives me the correctly formatted string '2011-04-24' print('Next Date ' . date_format($next_date_object,'Y-m-d')); //this gives me nothing. The output here is always blank So

How can I convert a Sql Server 2008 DateTimeOffset to a DateTime

笑着哭i 提交于 2019-11-26 19:00:29
I'm hoping to convert a table which has a DATETIMEOFFSET field, down to a DATETIME field BUT recalculates the time by taking notice of the offset. This, in effect, converts the value to UTC . eg. CreatedOn: 2008-12-19 17:30:09.0000000 +11:00 that will get converted to CreatedOn: 2008-12-19 06:30:09.0000000 or CreatedOn: 2008-12-19 06:30:09.0000000 + 00:00 -- that's a `DATETIMEOFFSET`, but `UTC`. Cheers :) RichardTheKiwi Converting using almost any style will cause the datetime2 value to be converted to UTC. Also, conversion from datetime2 to datetimeoffset simply sets the offset at +00:00 ,

Best practices with saving datetime & timezone info in database when data is dependant on datetime

自古美人都是妖i 提交于 2019-11-26 18:53:05
问题 There were quite a few questions about saving datetime & timezones info in DB but more on the overall level. Here I'd like to address a specific case. System specs We have an Orders system database It is a multi-tenant system where tenants can use arbitrary timezone (it is arbitrary but single timezone per tenant, saved in Tenants table once and never changes) Business rule needed to be covered in DB When tenant places an Order into the system, order number gets computed based on their local