Looking for a little help and some advise on a possible better way to do what I am trying to accomplish here. I am trying to get this script to write out the current time such as “Seven Fifty Three and Forty seconds”. I can accomplish that just fine, my problem comes in when the time is between x:01 and x:09. I can’t figure out how to make it say “Zero One, Zero Two” etc. or Zero seconds instead of the current “O’clock”.
Can anyone give me any advice on this and possibly a way to send it the entire time such as Get-WrittenTime -objTime (Get-Date)
Function Get-WrittenTime
{
Param
(
$objTime
)
$needsMore = $false
Switch ($objTime)
{
00 {$LongTime = "O'Clock"}
1 {$LongTime = "One"}
2 {$LongTime = "Two"}
3 {$LongTime = "Three"}
4 {$LongTime = "Four"}
5 {$LongTime = "Five"}
6 {$LongTime = "Six"}
7 {$LongTime = "Seven"}
8 {$LongTime = "Eight"}
9 {$LongTime = "Nine"}
10 {$LongTime = "Ten"}
11 {$LongTime = "Eleven"}
12 {$LongTime = "Twelve"}
13 {$LongTime = "Thirteen"}
14 {$LongTime = "Fourteen"}
15 {$LongTime = "Fifteen"}
16 {$LongTime = "Sixteen"}
17 {$LongTime = "Seventeen"}
18 {$LongTime = "Eighteen"}
19 {$LongTime = "Nineteen"}
20 {$LongTime = "Twenty"}
30 {$LongTime = "Thirty"}
40 {$LongTime = "Forty"}
50 {$LongTime = "Fifty"}
default {$needsMore = $true }
}
if ($needsMore)
{
$splitTime = $objTime -split ""
$x = 1
foreach ($split in $splitTime)
{
if ($split.length -gt 0)
{
if ($x -eq 1)
{
$z = $split + "0"
$fullTime += (Get-WrittenTime -objTime $z) + " "
$x++
}
Else
{
$fullTime += Get-WrittenTime -objTime $split
}
}
}
return $fullTime
}
return $LongTime
}
cls
$hour = Get-WrittenTime -objTime (Get-Date).Hour
$min = Get-WrittenTime -objTime (Get-Date).Minute
$sec = Get-WrittenTime -objTime (Get-Date).Second
Write-Output "$hour $min and $sec seconds"