Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DateTime represent how many bit in C#

Int, Float, Double, Decimal, DateTime .etc are value types. And I know:

Int:Represents a 32-bit signed integer.
Float:Represents a single-precision floating-point number(32-bit).
Double:Represents a double-precision floating-point number(64-bit).
...

But how many bit for DateTime? And why all value types in .NET are struct?

like image 593
jojo Avatar asked Aug 07 '14 04:08

jojo


People also ask

How many bits is a date?

DATE - a 32 bit binary integer containing the number of days since December 31, 1969 so a value of one (1) is 1980–01–01.

What is a DateTime value?

The DateTime value type represents dates and times with values ranging from 00:00:00 (midnight), January 1, 0001 Anno Domini (Common Era) through 11:59:59 P.M., December 31, 9999 A.D. (C.E.) in the Gregorian calendar. Time values are measured in 100-nanosecond units called ticks.

How many bytes does it take to represent time?

The internal representation of a time is a string of 3 bytes. Each byte consists of 2 packed decimal digits. The first byte represents the hour, the second byte the minute, and the last byte the second.


1 Answers

Based on here, DateTime represents 64-bit in C#:

Prior to the .NET Framework version 2.0, the DateTime structure contains a 64-bit field composed of an unused 2-bit field concatenated with a private Ticks field, which is a 62-bit unsigned field that contains the number of ticks that represent the date and time. The value of the Ticks field can be obtained with the Ticks property.

Starting with the .NET Framework 2.0, the DateTime structure contains a 64-bit field composed of a private Kind field concatenated with the Ticks field. The Kind field is a 2-bit field that indicates whether the DateTime structure represents a local time, a Coordinated Universal Time (UTC), or the time in an unspecified time zone. The Kind field is used when performing time conversions between time zones, but not for time comparisons or arithmetic. The value of the Kind field can be obtained with the Kind property.

like image 147
Matin Lotfaliee Avatar answered Oct 17 '22 04:10

Matin Lotfaliee