How not to string a date
The Weird and The Wonderful
2
Posts
2
Posters
0
Views
1
Watching
-
Here's another chunk of C++ that has been converted to VB.net:
Public Shared Function Strdate(ByVal dateBuf As String) As String ' timt(tnow) 'tm \*tnowVals 'time(&tnow) 'tnowVals = localtime(&tnow) Dim tnowVals As DateTime = DateTime.Now tnowVals = DateTime.Now If tnowVals.Year > 1999 Then 'If (tnowVals.tm\_year > 99) Then tnowVals.Subtract(TimeSpan.FromDays(365 \* 100)) ' tnowVals.tm\_year -= 100 End If dateBuf = tnowVals.ToString("MM/dd/yy") 'sprintf(dateBuf, "%02.02d/%02.02d/%02.02d", tnowVals.tm\_mon + 1, tnowVals.tm\_mday, tnowVals.tm\_year) Return dateBuf End Function
Notice that even the original C++ is faulty; it should use
%
(mod) rather than subtracting 100 years -- a Y3K bug. :sigh: -
Here's another chunk of C++ that has been converted to VB.net:
Public Shared Function Strdate(ByVal dateBuf As String) As String ' timt(tnow) 'tm \*tnowVals 'time(&tnow) 'tnowVals = localtime(&tnow) Dim tnowVals As DateTime = DateTime.Now tnowVals = DateTime.Now If tnowVals.Year > 1999 Then 'If (tnowVals.tm\_year > 99) Then tnowVals.Subtract(TimeSpan.FromDays(365 \* 100)) ' tnowVals.tm\_year -= 100 End If dateBuf = tnowVals.ToString("MM/dd/yy") 'sprintf(dateBuf, "%02.02d/%02.02d/%02.02d", tnowVals.tm\_mon + 1, tnowVals.tm\_mday, tnowVals.tm\_year) Return dateBuf End Function
Notice that even the original C++ is faulty; it should use
%
(mod) rather than subtracting 100 years -- a Y3K bug. :sigh: