PoshCode Archive  Artifact Content

Artifact 0c9d643d1b5514af8012a6db1fce11ef85b199b9769ae622dcd886755a688b71:

  • File Time-Stamp.ps1 — part of check-in [32c218cf20] at 2018-06-10 13:15:54 on branch trunk — This is a very simple function that returns a DateTime time stamp. I use it in scripts for noting times when actions occur like this Write-Host “$(Time-Stamp): Attempting to create directory.”; It’s a lot shorter than writing out the whole thing. You can also alias it to simplify the process: New-Alias -Name ts -Value Time-Stamp;. This way I use Write-Host “$(ts): Attempting to create directory.”; It outputs: 2011.07.17 05:01:10: Attempting to create directory. You can alter the value in the ToString to change the way the time stamp is formatted. (user: Will Steele size: 977)

# encoding: ascii
# api: powershell
# title: Time-Stamp
# description: This is a very simple function that returns a DateTime time stamp.  I use it in scripts for noting times when actions occur like this Write-Host “$(Time-Stamp): Attempting to create directory.”;  It’s a lot shorter than writing out the whole thing.  You can also alias it to simplify the process: New-Alias -Name ts -Value Time-Stamp;.  This way I use Write-Host “$(ts): Attempting to create directory.”;  It outputs: 2011.07.17 05:01:10: Attempting to create directory.  You can alter the value in the ToString to change the way the time stamp is formatted.
# version: 0.1
# type: function
# author: Will Steele
# license: CC0
# function: Time-Stamp
# x-poshcode-id: 2795
# x-archived: 2016-10-30T02:09:02
# x-published: 2011-07-17T15:03:00
#
#
function Time-Stamp
{
    return [System.DateTime]::Now.ToString("yyyy.MM.dd hh:mm:ss");
}

New-Alias -Name ts -Value Time-Stamp;