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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:23:29+00:00 2026-05-30T16:23:29+00:00

If I have a DateTime instance which represents a valid UTC time, and an

  • 0

If I have a DateTime instance which represents a valid UTC time, and an offset that converts that DateTime to the time zone where it applies, how do I construct a DateTimeOffset instance to represent this?

var utcDateTime = new DateTime(2011, 02, 29, 12, 43, 0, /*DateTimeKind.Utc*/);
var localOffset = TimeSpan.FromHours(2.0);

var dto = ...

// Here the properties should be as follows;
// dto.UtcDateTime = 2011-02-29 12:43:00
// dto.LocalDateTime = 2011-02-29 14:43:00

Perhaps I’m not understanding the DateTimeOffset structure correctly, but I’m unable to get the expected output.

Thanks in advance

  • 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-05-30T16:23:30+00:00Added an answer on May 30, 2026 at 4:23 pm

    Looks like you want:

    var utcDateTime = new DateTime(2012, 02, 29, 12, 43, 0, DateTimeKind.Utc);
    var dto = new DateTimeOffset(utcDateTime).ToOffset(TimeSpan.FromHours(2));
    

    Note that I changed the year from 2011 (which is not a leap year and does not have 29 days in February) to 2012.

    Test:

    Console.WriteLine("Utc = {0}, Original = {1}", dto.UtcDateTime, dto.DateTime);
    

    Output:

    Utc = 2/29/2012 12:43:00 PM, Original = 2/29/2012 2:43:00 PM
    

    Do note that you probably don’t want the LocalDateTime property, which may represent the instant in time as of the local system’s timezone.

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

Sidebar

Related Questions

I have an Event model that includes a start time field, which is stored
I have a DateTime object that I need to print in a custom gridlike
I have an datetime object that I want to remove one hour to display
I have a DateTime which I want to store in a Date MySQL column.
I have a DATETIME field. I would like to select all the records that
I have a datetime column in db that I want to transform into a
I have the following classes: Defect - represents a type of data that can
I have got a Sales table which has fields like upgrade[yes/no] date upgraded[datetime] user[username]
I have a bank/collection which caches instances of objects in memory so that each
I have a SQL Server function which converts a nvarchar day duration setting into

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.