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

  • Home
  • SEARCH
  • 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 906857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:27:22+00:00 2026-05-15T16:27:22+00:00

If I run a snippet like: bool areTheyTheSame = DateTime.UtcNow == DateTime.Now what will

  • 0

If I run a snippet like:

bool areTheyTheSame = DateTime.UtcNow == DateTime.Now

what will I get? Does the DateTime returned know its timezone such that I can compare?

My specific problem is that I’m trying to build a cache-like API. If it takes a DateTime AbsoluteExpiration, do I have to enforce that users of my API know whether to give me a UTC time or a timezone-based time?

[Edit] This SO question is extremely relevant to my issue as well: Cache.Add absolute expiration – UTC based or not?

[Edit] Just to clarify for future readers, the DateTimeKind is what is different. The Undefined DateTimeKind’s are often a problem, which is what you get when you pull one out of a database, for instance. Set the DateTimeKind in the DateTime constructor…

[Edit] JonSkeet wrote a lovely blog post condemning this behavior and offering a solution: http://noda-time.blogspot.co.uk/2011/08/what-wrong-with-datetime-anyway.html

  • 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-15T16:27:22+00:00Added an answer on May 15, 2026 at 4:27 pm

    Did you actually try the snippet yourself?

    They’re different, and a straight comparison doesn’t account for the difference, but you can convert local to UTC by calling ToUniversalTime.

    var now = DateTime.Now;
    var utcNow = DateTime.UtcNow;
    
    Console.WriteLine(now);                         // 12/07/2010 16:44:16
    Console.WriteLine(utcNow);                      // 12/07/2010 15:44:16
    Console.WriteLine(now.ToUniversalTime());       // 12/07/2010 15:44:16
    Console.WriteLine(utcNow.ToUniversalTime());    // 12/07/2010 15:44:16
    
    Console.WriteLine(now == utcNow);                         // False
    Console.WriteLine(now.ToUniversalTime() == utcNow);       // True
    Console.WriteLine(utcNow.ToUniversalTime() == utcNow);    // True
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

if you run this snippet of code(put it in form1) in a fresh new
I have a problem when I run this snippet of code on the emulator
I run the following html snippet in IE8 and IE7 with non-English characters (we
I need to run a PHP code snippet in a Drupal template and prevent
I have following code snippet that i use to compile class at the run
When I run this snippet of code: string[] words = new string[] { foo,
I want a code snippet editor for VS2008. I'd like to just hit a
What is the safest way to make a snippet of code run at the
The following code doesn't appear to run when executed by code: Stored procedure snippet:
I'm trying to create a Textmate snippet, but have run into some difficulties. Basically,

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.