Valhalla Legends Forums Archive | .NET Platform | C#: Millisecond Offset date

AuthorMessageTime
DaRk-FeAnOr
How do you get a millisecond offset date in C# (like GetTickCount() in visual basic)? Thanks for any help you can offer.
December 5, 2003, 5:36 PM
K
Environment.TickCount
December 5, 2003, 6:45 PM
UserLoser.
*knows nothing about .NET stuff* SystemTime struct
December 6, 2003, 9:09 PM
Myndfyr
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:

[code]
typedef struct _SYSTEMTIME {
WORD wYear;
WORD wMonth;
WORD wDayOfWeek;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
} SYSTEMTIME;
[/code]
is nearly completely useless as this is a .NET forum and it is an MFC struct.
December 6, 2003, 9:38 PM
Kp
[quote author=Myndfyre link=board=37;threadid=4091;start=0#msg33994 date=1070746712]
SYSTEMTIME is nearly completely useless as this is a .NET forum and it is an MFC struct.[/quote]

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"!
December 7, 2003, 12:55 AM
St0rm.iD
EWWWW at that terrible, terrible epoch!
December 7, 2003, 1:17 AM
UserLoser.
Like I said, isn't SystemTime struct correct?

In VB, shouldn't be too hard to port to .NET:
[code]
Dim ST as SomeSystemTrimStruct
Dim SomeString as String

SomeString = Right("00" & ST.wMilliseconds)
[/code]
December 7, 2003, 2:24 AM
K
[quote author=UserLoser. link=board=37;threadid=4091;start=0#msg34047 date=1070763850]
Like I said, isn't SystemTime struct correct?

In VB, shouldn't be too hard to port to .NET:
[code]
Dim ST as SomeSystemTrimStruct
Dim SomeString as String

SomeString = Right("00" & ST.wMilliseconds)
[/code]
[/quote]

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.
December 7, 2003, 5:20 AM
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. :)
December 7, 2003, 6:53 AM
Myndfyr
[quote author=Kp link=board=37;threadid=4091;start=0#msg34028 date=1070758517]
[quote author=Myndfyre link=board=37;threadid=4091;start=0#msg33994 date=1070746712]
SYSTEMTIME is nearly completely useless as this is a .NET forum and it is an MFC struct.[/quote]

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"!
[/quote]

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.
December 8, 2003, 11:25 PM

Search