[英]Powershell | How to calculate current date -5 days to Epoch time?
So I'm trying to write a script to get the current date and subtrace 5 days from it.所以我正在尝试编写一个脚本来获取当前日期并从中减去 5 天。 Then change that date to Epoch time.
然后将该日期更改为纪元时间。 However it's not really working out properly.
但是,它并没有真正正常工作。 I've currently been unable to subtract the 5 days from it, this is currently my script:
我目前无法从中减去 5 天,这目前是我的脚本:
$unixTime = [int][double]::Parse((Get-Date -UFormat %s))
return $unixTime
I've also tried the following:我还尝试了以下方法:
$unixTime = [int][double]::Parse(((Get-Date).AddDays(-5) -UFormat %s)))
return $unixTime
And also:并且:
$unixTime = [int][double]::Parse((Get-Date) -UFormat %s).AddDays(-5))
return $unixTime
But so far I haven't been able to make it work.但到目前为止,我还无法让它发挥作用。 Does anyone know what I have to change about this calculation to make it work?
有谁知道我必须对此计算进行哪些更改才能使其正常工作? Thank you very much
非常感谢
Would this be what you're after?这会是你所追求的吗?
Get-Date $((Get-Date).AddDays(-5)) -UFormat +%s
An alternative is to use a new DateTimeOffset
object instead.另一种方法是改用新的
DateTimeOffset
object。
[System.DateTimeOffset]::Now.AddDays(-5).ToUnixTimeMilliseconds()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.