-1

So I am trying to format my date properly in a readable format.

Here is my code.

WScript.Echo(DateDiff("s", "01/01/1970 00:00:00", Now()))

Function sprintf(sFmt, aData)
   With CreateObject("System.Text.StringBuilder")
      .AppendFormat_4 sFmt, (aData)
      sprintf = .ToString()
      .Length = 0
   End With
End Function

Dim CurrTime  : CurrTime = Now()
Dim Elapsed   : Elapsed = Timer()
Dim MilliSecs : MilliSecs = Right("000" & Int((Elapsed - Int(Elapsed)) * 1000), 3)

'echo "Date: " . date("D, d M Y H:i:s O");
'Date: Tue, 18 Nov 2014 15:57:11 +0000

WScript.Echo "Date: ", sprintf( "{0:yyyy/MM/dd HH:mm:ss}", Array(CurrTime)) & "." & MilliSecs

The output i am trying to achieve is this

Date: Tue, 18 Nov 2022 15:57:11 +0000

But i am missing allot

C0nw0nk
  • 870
  • 2
  • 13
  • 29
  • It is useful but i already made a soloution i posted it below thanks for the help :) – C0nw0nk Jun 12 '22 at 14:54
  • If you're already borrowing objects like `System.Text.StringBuilder` from .NET, why wouldn't you just do `System.DateTime.Now.ToString` and pass a [format specifier](https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings)? – Matt Johnson-Pint Jun 12 '22 at 16:15

1 Answers1

-2
Function sprintf(sFmt, aData)
   With CreateObject("System.Text.StringBuilder")
      .AppendFormat_4 sFmt, (aData)
      sprintf = .ToString()
      .Length = 0
   End With
End Function
Dim CurrTime  : CurrTime = Now()
WScript.Echo WeekdayName(Weekday(Now()),True) & ", " & Day(Now()) & " " & MonthName(Month(Now()),True) & " " & sprintf( "{0:yyyy HH:mm:ss}", Array(CurrTime)) & " +0000"

Figured out a way to get the output i wanted.

C0nw0nk
  • 870
  • 2
  • 13
  • 29