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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:11:48+00:00 2026-06-12T08:11:48+00:00

I want to convert my time to universal time when I store date time

  • 0

I want to convert my time to universal time when I store date time in database and convert back to system time when I retrieve from the database.

Both of them I have done it success fully by creating functions ConvertToLocalTime()
and ConvertToUniversalTime().

The code for convert to local time is given below:

    public void ConvertToLocalTime()
    {
        string szTimezoneinfoid = TimeZoneInfo.Local.Id.ToString();
        TimeZoneInfo tzInfo = TimeZoneInfo.FindSystemTimeZoneById(szTimezoneinfoid);

        this.m_dtCreatedDate = TimeZoneInfo.ConvertTimeFromUtc(m_dtCreatedDate, tzInfo);
    }

When I call a function Shipment.ConvertToLocalTime() it changes the shipment created date to local time till this it works fine.

Now if I call the Shipment.ConvertToLocalTime() again then it consider the local time again as UTC and convert it to local time.

Is there any way to block the conversion to local time if it is already in local time?

Does there any way that we can get the time zone of the datetime?

  • 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-12T08:11:49+00:00Added an answer on June 12, 2026 at 8:11 am

    I’m not sure exactly what’s going wrong in your example, but if you simply want to get a date/time you know to be UTC from the database and convert it to local time, you can do the following:

    var dbTime = //whatever, from database.
    var utcTime = DateTime.SpecifyKind(dbTime, DateTimeKind.Utc);
    var localTime = utcTime.ToLocalTime();
    

    In my own project, I check dbTime.Kind != DateTimeKind.Local first, jut in case my data reader has decided to start performing the conversion for me.

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

Sidebar

Related Questions

I want to convert time to hh:mm from hh:mm:ss it comes from database (my
So I have datetime objects in UTC time and I want to convert them
I want to convert South African time to any universal time. I have the
I have a date/time string like 2012-01-13 04:37:20 but I want to convert it
I have two inputs Time and Date. I want to convert these fields to
I'm getting date-time from a source as 20110731183330. I want to convert it to
I have a date time in milliseconds, e.g. 1347616929, and I want to convert
I have a location (city, state), date, and time and I want to convert
I have seconds from epoch time and want to convert it to Day-Month-Year HH:MM
I have a Python datetime object that I want to convert to unix time,

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.