I'm using Powershell to run an AWS backup to S3 buckets and write out a continuing log file. I need to show how long the backup takes in the log file. I've tried a number of methods and can't seem to find one that works. If I remove the -Format... command it shows the time difference but it's ugly. This code is one of my many attempts
$StartTime = get-date
>>> RUN THE BACKUP
$EndTime1 = Get-Date
$DURATION = $EndTime1 - $StartTime -Format 'hh:mm:ss'
Either use ToString()
directly on the resulting TimeSpan
, or use the -f
string format operator:
$duration.ToString('hh\:mm\:ss')
# or
'{0:hh\:mm\:ss}' -f $duration
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.