如何将数字添加到变量中包含的另一个数字?
$t0 = Get-date -UFormat "%H%M"
$t1 = $t0 + 10
Run Code Online (Sandbox Code Playgroud)
所以,如果$ t0是1030,我会将$ t1的值设为1040.
[int]在将值赋值给$ t0之前强制执行(get-date -uformat返回[string]类型):
[int]$t0 = Get-date -UFormat "%H%M"
$t1 = $t0 + 10
Run Code Online (Sandbox Code Playgroud)
如果更改顺序,powershell的强制功能会给出预期值:
$t0 = Get-date -UFormat "%H%M"
$t1 = 10 + $t0
Run Code Online (Sandbox Code Playgroud)
因为第二个操作数被转换为第一个操作数的类型
| 归档时间: |
|
| 查看次数: |
23123 次 |
| 最近记录: |