Logo for kapa dot dev
Published on

DateTime in .NET - Things I learned (#1?)

Authors

Here's what I looked like while learning about DateTime in .NET:

Mr. Incredible going from Happy to Sad

What do I think they are?

Like with strings, I can't be too sure.

I know that at its core, DateTime mostly works on some form of integer as "ticks" to determine the current time. DateTime comparison and addition then becomes quite easy.

Though I couldn't say what the default Time Zone information is and how that gets converted.

5 things that I learned while looking at DateTime

  • DateTime data is stored as a ulong but is actually treated as bytes
    • The first 62 Bits is the value of 100-nanosecond ticks
    • Bits 63-64 are to denote DateTimeKind
  • C# DateTimes have a range of 01/01/0001 12:00:00 AM until 31/12/9999 11:59:59 PM
  • The DateTimeKind Enum can be helpful for ensuring you're dealing with DateTimes Consistently
  • Wtf is the | Operator?
    • It's called a Bitwise OR Operator
    • It's REALLY interesting, and is used to combine add Bits together.
    • I hate it
  • But what are Structs actually?

What were the differences?

I thought that the DateTime data was just a simple ulong, but it's clear that it's being used in a more complex way than I initially thought. I feel like I've barely scratched the surface on this one, so I'm excited to jump back into it later.