0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

PowerShellのTimeSpanで1ミリ秒以下を入力したい

Posted at

PowerShellのTimeSpanを取り扱うコマンドレットとしては、New-TimeSpanコマンドレットがあります。

今回、TimeSpanに1ミリ秒以下を入力したいと思いNew-TimeSpan -Milliseconds 0.1としたら下記のようになってしまいました。

image.png

みごとの0になってしまい、Millisecondsオプションに小数点を入れるのはだめそうです。

本記事はこの対策として、ちょっと色々と試してみたメモ。

今回実施している環境

  • Windows 10 21H2
  • PowerShell 7.4.0-preview.3

New-TimeSpanでTimeSpanオブジェクトを作成して、10でわってみる。

(New-TimeSpan -Milliseconds 1) /10

image.png

Ticks が 1000 になってますし、 他項目も0.1ミリ秒になっていてよさそうです。

timespan の FromMillisecondsメソッドは小数点もいれられる

コマンドレットでTimeSpanオブジェクトを生成する事にこだわらなければ。
下記のように記述する事もできました。

[timespan]::FromMilliseconds(0.1)

image.png

総評

PowerShellでTimeSpanオブジェクトの細かい時間を積み上げる計算をしようとして、TimeSpanオブジェクトに1ミリ秒以下ってどうやって入力すれば? となりましたが。

本記事の方法でとりあえず入力はできました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?