Noon three moment has arrived, execution, Liusto, now in the end is not noon, can let PowerShell tell me?
Ok no problem. From 23 o'clock to 2 o'clock in the morning from the night to belong to the midnight, every two hours an hour, in turn, "Kaniko Chen has not Shin hai."
function to get the current hour
Implemented with PowerShell script:
function Get-chinatimealias
{
param (
[Validaterange (0,23)]
[int] $Hour = (get-date). Hour
)
$timeAliasArray = ' Kaniko chen has not Shin hai '
[int] $index =0
if ($hour-eq) {$index =11}
else{
$ Index=[math]::floor (($hour +1)% 23/2)
} return
$timeAliasArray [$index] + "when"
}
Get the current hour
Ps> get-date
September 17, 2014 23:17:58
Copy Code code as follows:
Ps> Get-chinatimealias
Midnight
Gets the hour corresponding to the specified number of hours
Copy Code code as follows:
Ps> Get-chinatimealias 12
Noon
Print all hours and corresponding time periods
Input
$timeArray =@ (+0..22) for
($i =0; $i-lt $timeArray. Length; $i = $i +2)
{
$startHour = $timeArray [$i]. ToString (). PadLeft (2, ' 0 ')
$endHour = $timeArray [$i +1]. ToString (). PadLeft (2, ' 0 ')
$timeAlias = Get-chinatimealias $timeArray [$i]
[pscustomobject]@{
hour = $timeAlias;
Time period = (' {0}:00-{1}:59 '-f $startHour, $endHour)
}}
Output
Copy Code code as follows:
Hour time period
-- ---
Midnight 23:00-00:59
Shing 01:00-02:59
Yinshi 03:00-04:59
Shing 05:00-06:59
Chen Shi Shenzhou 07:00-08:59
Sishi 09:00-10:59
Noon 11:00-12:59
West 13:00-14:59
Have 15:00-16:59
Youshi 17:00-18:59
Shing 19:00-20:59
Haishi 21:00-22:59
Summarize
The string itself is an array of characters, and there is no need to save Kaniko and so on separately.
Using the model and 22 special treatment to evade the individual conditions of every hour to judge.