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 9173717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:37:52+00:00 2026-06-17T16:37:52+00:00

I need to convert UTC date strings to DateTimeOffsets . This must work with

  • 0

I need to convert UTC date strings to DateTimeOffsets.

This must work with a timezone which differs from the computers timezone.
E.g. current computer timezone is +02:00, but I want to create a DateTimeOffset with offset -4:00.

I already read lot of questions here on stackoverflow, but none of them solved my problem.

That is what I need to do:

Input: “2012-11-20T00:00:00Z”

Output: DateTimeOffset with:

  • UtcDateTime of 2012-11-20 00:00
  • the correct Utc offset for the defined timezone (01:00 in this example)
  • LocalDateTime: 2012-11-20 01:00 (= UtcDateTime + Offset)

Of course daylight saving must be taken into account.

edit:
To make things even clearer, please try to complete the following code snippet:

DateTimeOffset result;
const string dateString = "2012-11-20T00:00:00Z";
var timezone = TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time"); //this timezone has an offset of +01:00:00 on this date

//do conversion here

Assert.AreEqual(result.Offset, new TimeSpan(1, 0, 0));  //the correct utc offset, in this case +01:00:00
Assert.AreEqual(result.UtcDateTime, new DateTime(2012, 11, 20, 0, 0, 0)); //equals the original date
Assert.AreEqual(result.LocalDateTime, new DateTime(2012, 11, 20, 1, 0, 0));
  • 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-17T16:37:53+00:00Added an answer on June 17, 2026 at 4:37 pm

    Here is the solution you are looking for:

    const string dateString = "2012-11-20T00:00:00Z";
    TimeZoneInfo timezone = TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time"); //this timezone has an offset of +01:00:00 on this date
    
    DateTimeOffset utc = DateTimeOffset.Parse(dateString);
    DateTimeOffset result = TimeZoneInfo.ConvertTime(utc, timezone);
            
    Assert.AreEqual(result.Offset, new TimeSpan(1, 0, 0));  //the correct utc offset, in this case +01:00:00
    Assert.AreEqual(result.UtcDateTime, new DateTime(2012, 11, 20, 0, 0, 0)); //equals the original date
    Assert.AreEqual(result.DateTime, new DateTime(2012, 11, 20, 1, 0, 0));
    

    Note that you were incorrectly testing the .LocalDateTime property – which is always going to convert the result to the local time zone of the computer. You simply need the .DateTime property instead.

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

Sidebar

Related Questions

I need to parse a date/time string from user input, and convert to UTC
I need to convert an existing (datetime fields) db from local time ut UTC.
I need to convert this string date 2011-06-25T11:00:26+01:00 into a long like value. I
I need to convert the Timezone of my windows mobile 6.5 application to UTC
I need to convert hierarchical data (AVRO data, which boils down to JSON) into
I need to convert keys from type string to hash. The name of all
I need to convert UTC time, (on ec2 instance) to PST. I am trying
I need to convert default mysql modtimes into UTC formated datetimes using xslt. I
I have a string containing a local date/time and I need to convert it
I'm looking for an JavaScript algorithm to convert local calendar date-times into UTC milliseconds

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.