Do you need all the most important bits? (e.g. what year)
Do you need all the least significant bits? (e.g. sub-nanosecond precision)
How long do you need to measure the interval?
If you only need millisecond precision, why not lose the least significant bits.
int timeStamp = (int)(DateTime.Now.Ticks >> 10)
change
The OP wants to save time using recently used items: if this is a user choice for a single user, you probably don't want anything shorter than a second! since 10 ^ 7 ticks per second, log (10 ^ 7) / log (2) = 23 redundant bits in a long value!
So how much space do you need? Well, your values ββshould indicate year, month, day, hour, minute and second; In a year, about 32 million seconds = about 24 bits. add 3 bits if you want to keep the last 10 years. Therefore, it easily fits into int32. I suggest
int timeStamp = (int)(DateTime.Now.Ticks >>23)
Sanjay manohar
source share