Military time to standard time RRS feed

  • Question

  • The script below works great; however, the log files appear in Military time. Is there a way to force the script to appear in standard time?

    Log In Mon 08/21/2017 20:54:19.62 NWILL-39HBP22 
    Log Off Mon 08/21/2017 20:56:24.23 NWILL-39HBP22 
    Log In Mon 08/21/2017 20:57:18.17 NWILL-39HBP22 

    rem The following line creates a rolling log file of usage by workstation
    echo Log Off %Date% %TIME% %USERNAME% >> \\enc\Data\Loginandout$\Logs\computer\%COMPUTERNAME%.log

    rem The following line creates a rolling log file of usage by user
    echo Log Off %Date% %TIME% %COMPUTERNAME% >> \\enc\Data\Loginandout$\Logs\users\%USERNAME%.log

    • Moved by Bill_Stewart Monday, October 2, 2017 9:41 PM This is not "scripts on demand"
    Tuesday, August 22, 2017 1:14 AM

All replies

  • What is military time?

    This is just normal local time. "Mon 08/21/2017 20:54:19.62 "

    Windows an the whole computer industry use a 24 hour clock.

    In "batch" %time% is the time for the computer. "Batch" does not support time conversion.  If you need time conversion consider using PowerShell.  "batch" is pretty much obsolete.


    Tuesday, August 22, 2017 1:43 AM
  • Here is my powershell script. When the batch files runs, a rolling log file with the details is created. How do I get powershell to do the same

    $timeformat='MM-dd-yyyy hh:mm:ss tt'
    $time = (Get-Date).ToString($timeformat)
    $table=  New-Object -TypeName PSObject -Property @{

                'Date/Time' = $time
                'Username' = $env:username
                'ComputerName'= $env:COMPUTERNAME
               # 'IPv4 Address' = Test-Connection -ComputerName $env:COMPUTERNAME -Count 1 | foreach { $_.ipv4address }
               # 'IPv6 Address' = Test-Connection -ComputerName $env:COMPUTERNAME -Count 1 | foreach { $_.ipv6address }  
           'Notes/Action' = "Logon"
    } | Select date/time, username, computername, 'IPv4 Address', 'IPv6 Address', notes/action
    $table | Export-Csv "\\E\Data\Loginandout$\$env:username.csv" -nti

    Tuesday, August 22, 2017 7:57 AM
  • A rolling log file?  do you mean you want it to append to the file every time it runs ?  If so you can use -append

    Export-Csv -append 

    Tuesday, August 22, 2017 8:25 AM
  • Hi,

    while I still consider this to be the only legal* way to write a timestamp:

    (Get-Date).ToString("yyyy-MM-dd HH:mm:ss")

    You may want to change your ToString(...) call to this:

    (Get-Date).ToString('MM-dd-yyyy hh:mm:ss tt', [System.Globalization.CultureInfo]::InvariantCulture)

    In order to ensure it will run equally well, no matter the culture settings of the server you are running it under.


    *Not actual legal advice. Taking no responsibility for damages caused by holy wars spawned by this sentence ;).

    There's no place like

    Tuesday, August 22, 2017 11:45 AM