Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7846285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:31:58+00:00 2026-06-02T17:31:58+00:00

.NET Web Service I have a .NET web service which returns json formatted DateTime’s.

  • 0

.NET Web Service
I have a .NET web service which returns json formatted DateTime’s.
The json representation of a DateTime specified by Microsoft is for example:
/Date(1302847200000+0200)/
This is according to MSDN – Stand-Alone JSON Serialization the millisecond offset since the first of January 1970 in UTC before the +/- sign and after the sign the time zone offset of the local time to GMT. So for this serialization the DateTime value must be converted from the web service’s local time to UTC.

Android (java) Client
In my Android application, which receives the web service results, I parse json using Gson. Because the .NET DateTime json serialization is not a standard (according to Microsoft there is no such standard for DateTime) gson is not able to parse such formatted dates. I wrote a Date TypeAdapter which does the serialization and deserialization on the client side.

So this seems to work fine. DateTime exchange from and to service in UTC. It would be fine, if .NET’s DateTime and Java’s Calendar would regard totally the same rules when it comes to conversion of local to UTC time.

An example: Switzerland has DST (Daylight Saving Time) since 1979. Java knows that DST did not exist before. .NET assumes it exists since ever. So when a date in summer before 1979 is converted from .NET to UTC and from Java back to Local time (for presentation), then this date loses an hour in the same time zone.

Question
How to face that problem? Is there any mistake I am doing in the described data exchange.
I thought about many different solutions. The only way which i can imagine to work properly is to replace the .NET json DateTime Serialization/Deserialization. This of course is not a favoured one…

Thanks for your time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T17:32:00+00:00Added an answer on June 2, 2026 at 5:32 pm

    Don’t use the standard .NET Json serializer it will cause you too many headaches than you need if you are working between Java and .NET. As you found out, Microsoft uses a format that most people don’t use.

    The best serializer is Newtonsoft’s Json.NET (NuGet page) it’s become a de facto standard for .NET developers. They have a great DateTime serialization/deserialization options that are simple to use. For more information check out their blog post on DateTime. I tend to use ISO 8601, which is their default format in Json.NET v4.5.

    I used to work on an enterprise application that worked communicated via Json with many different products create in a range of languages and Json.NET made that inter-product communication trivial.

    Update on dealing with Switzerland’s DateTime

    Since you’re specifying a generic Central European Standard Time, .NET doesn’t know what Switzerland’s date time rules are specifically. To deal with Switzerland you’re going to need to give .NET the Switzerland rules. Looking at Wikipedia it started in 1981, so creating a custom TimeZoneInfo would look something like the following:

    // UTC Time
    var date1 = new DateTime(1969, 4, 20, 2, 20,00, DateTimeKind.Utc);
    Console.WriteLine("Date 1: " + date1.ToString() + " - " + date1.IsDaylightSavingTime());
    
    // CEST
    var timezone = TimeZoneInfo.FindSystemTimeZoneById("Central European Standard Time");
    var date2 = TimeZoneInfo.ConvertTimeFromUtc(date1, timezone);
    Console.WriteLine("Date 2: " + date2.ToString() + " - " + date2.IsDaylightSavingTime() + " " + timezone.IsAmbiguousTime(date2));
    
    // Switzerland
    var cesAdjRule = timezone.GetAdjustmentRules().Single();
    var switzerlandStartTransition = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(
            cesAdjRule.DaylightTransitionStart.TimeOfDay,
            cesAdjRule.DaylightTransitionStart.Month, cesAdjRule.DaylightTransitionStart.Week,
            cesAdjRule.DaylightTransitionStart.DayOfWeek
    );
    var switzerlandAdjustmentRule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(
        new DateTime(1981, 1, 1),
        DateTime.MaxValue.Date,
        cesAdjRule.DaylightDelta,
        switzerlandStartTransition,
        cesAdjRule.DaylightTransitionEnd
    );
    TimeZoneInfo.AdjustmentRule[] adjustments = {switzerlandAdjustmentRule};
    
    var switzerlandTimeZone = TimeZoneInfo.CreateCustomTimeZone("Switzerland",
                                                                timezone.BaseUtcOffset,
                                                                "Switzerland",
                                                                "Switzerland",
                                                                "Switzerland",
                                                                adjustments, false);
    
    var date3 = TimeZoneInfo.ConvertTimeFromUtc(date, timezone, switzerlandTimeZone);
    Console.WriteLine("Date 3: " + date3.ToString() + " - " + date3.IsDaylightSavingTime() + " " + timezone.IsAmbiguousTime(date3));
    

    The output of that would look like this (at least on my machine):

    Date 1: 4/20/1969 2:20:00 AM - False
    Date 2: 4/20/1969 4:20:00 AM - True - False
    Date 3: 4/20/1969 3:20:00 AM - True - False
    

    As you can see, IsDaylightSavingsTime is True on the DateTime, but TimeZoneInfo correctly converted our time. Trying a few other combinations looks good too. You can also convert between the CEST that it thinks you have and Switzerland with TimeZoneInfo.CovertTime().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a .NET web service which returns JSON, including a date in string
I have a .net JSON web service which returns a json string when queried.
I have a web service built on .NET which returns XmlDocument. I'm reading it
I have an ASP.NET web service which does some heavy lifting, like say,some file
I have a .NET web service which is publically accessible since it needs to
I have an ASP.net web service that I'm using for a web application which
I have a .net web application which has a reference to a web service.
I have a medium sized application that runs as a .net web-service which I
I have a ASP.NET web service decorated with System.Web.Script.Services.ScriptService() so it can return json
I have a webservice (.NET) which returns JSON result. The iOS application consumes that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.