• Welcome to Valhalla Legends Archive.
 

C#: Millisecond Offset date

Started by Dark-Feanor, December 05, 2003, 11:36 AM

Previous topic - Next topic

Dark-Feanor

How do you get a millisecond offset date in C# (like GetTickCount() in visual basic)? Thanks for any help you can offer.
- Feanor[xL]
clan exile
Firebot
iago: "caps lock is like cruise control for cool"

K


UserLoser.

#2
*knows nothing about .NET stuff* SystemTime struct

MyndFyre

#3
From http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemEnvironmentClassTickCountTopic.asp :

Environment.TickCount property:
---------
Property Value
A 32-bit signed integer containing the amount of time in milliseconds that has passed since the last time the computer was started.

Remarks
The value of this property is derived from the system timer and is stored as a 32-bit signed integer. Therefore, the elapsed time will wrap around to zero if the system is run continuously for 24.9 days.

The resolution of the TickCount property cannot be less than 500 milliseconds.

The TickCount property handles an overflow condition by resetting its value to zero. The minimum value returned by TickCount is 0.

TickCount is different from the Ticks property, which is the number of 100-nanosecond intervals that have elapsed since 1/1/0001, 12:00am.

Use the DateTime.Now property to obtain the current local date and time on this computer.

From http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatetimeclasstickstopic.asp :

DateTime.Ticks property
------
Property Value
The number of ticks that represent the date and time of this instance. The value is between MinValue and MaxValue.

Remarks
The value of this property is the number of 100-nanosecond intervals that have elapsed since 12:00 A.M., January 1, 0001.


From http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_SYSTEMTIME_Structure.asp :

The SYSTEMTIME structure:


typedef struct _SYSTEMTIME {
  WORD wYear;
  WORD wMonth;
  WORD wDayOfWeek;
  WORD wDay;
  WORD wHour;
  WORD wMinute;
  WORD wSecond;
  WORD wMilliseconds;
} SYSTEMTIME;

is nearly completely useless as this is a .NET forum and it is an MFC struct.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Kp

Quote from: Myndfyre on December 06, 2003, 03:38 PM
SYSTEMTIME is nearly completely useless as this is a .NET forum and it is an MFC struct.

This is incorrect.  SYSTEMTIME is part of standard Windows headers, and can be accessed from any native code (as well as from things that can directly call native code with pointers to UDTs).  It is not "an MFC struct"!
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Banana fanna fo fanna

EWWWW at that terrible, terrible epoch!

UserLoser.

Like I said, isn't SystemTime struct correct?

In VB, shouldn't be too hard to port to .NET:

Dim ST as SomeSystemTrimStruct
Dim SomeString as String

SomeString = Right("00" & ST.wMilliseconds)

K

Quote from: UserLoser. on December 06, 2003, 08:24 PM
Like I said, isn't SystemTime struct correct?

In VB, shouldn't be too hard to port to .NET:

Dim ST as SomeSystemTrimStruct
Dim SomeString as String

SomeString = Right("00" & ST.wMilliseconds)


Of course, but there's no reason to use the native calls when there is a managed version as well.  By using the Windows API, you lose any chance of running your program under mono.

Kp

WINE > Mono.  If you're going to emulate Microsoft, at least do it natively. :P

Also, I feel it's worth noting that whoever picked how to design the date/time functionality that was brought up in this thread was an idiot.  If he had used an unsigned integer, he could have reached 49.7 days before wrapping (or much much more if he'd used a long, either signed or unsigned).  I agree with $t0rm too - that's a horrible epoch.  If you're going to go choosing something in the distant past, follow the standard and use seconds since 1/1/1970. :)
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

MyndFyre

Quote from: Kp on December 06, 2003, 06:55 PM
Quote from: Myndfyre on December 06, 2003, 03:38 PM
SYSTEMTIME is nearly completely useless as this is a .NET forum and it is an MFC struct.

This is incorrect.  SYSTEMTIME is part of standard Windows headers, and can be accessed from any native code (as well as from things that can directly call native code with pointers to UDTs).  It is not "an MFC struct"!

Hey, I'm just passing on what the MSDN site said - that it was with MFC.

But regardless, as K said, there is no reason to use this struct in a managed environment.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.