1

I have a long-term problem. I watch on the web, but I did not find right answer. When I send data from WebAPI-Angular-Controller to Controller is a problem with formatting date. There are real data:

My TimeZone is UTC + 1

MS SQL: Column type: DateTime2(3) value: 4.7.2015 20:00:00

The client receives the following formats based on the following criteria: When I edit on WebApiConfig config.Formatters.JsonFormatter.SerializerSettings.Converters.Add (new IsoDateTimeConverter DateTimeStyles = {} DateTimeStyles.AdjustToUniversal); The client receives 2015-07-04T03: 00: 00Z and this {{time | date 'HH: mm: ss'}} show wrong time. It is show time + 2 hours -> 22:00:00 -> I tried {{time | date 'HH: mm: ss' 'UTC'}}, bud show this time - 1 hour -> 19:00:00.

When I edit on WebApiConfig config.Formatters.JsonFormatter.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;, so it is the same as first example.

When I edit on WebApiConfig config.Formatters.JsonFormatter.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local, so it is the same as first example excepting client receive data; they look like 2015-07-04T22: 00: 00 + 02: 00

When I edit on WebApiConfig config.Formatters.JsonFormatter.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Undefined, client receive data; they look like 2015-07-04T20: 00: 00 -> it is look OK, bud problem is elsewhere. I need this time (20:00:00) - curent time (f.e. 10:00:00) = 10:00:00 diff time, but angular show 11:00:00, why?

there is source from angularController

var d1 = new Date(bq.Done_Time)
var d2 = new Date()

bq.Time_Left = new Date(bq.Done_Time).getTime() - new Date().getTime()

Is the problem on server side or client side? And how can I resolve it?

Thank you very much for your valuable suggestions

Mediel
  • 11
  • 1
  • You're missing the part about how the date gets put into the sql database to begin with. Are you storing UTC values? (you should be). You should not rely on the server's time zone at all. Read [Daylight saving time and time zone best practices](http://stackoverflow.com/a/2532962/634824) – Matt Johnson-Pint Jul 03 '15 at 17:44

0 Answers0