I am getting a EPOC time from a remote machine, which is present in different timezone compare to the local system. I want to add a 7-8minute time to that EPOC time. Is there any way I can do this in powershell?
The EPOCH time is with precision rfc3339
For example, I have current time 1641960490800 as time of the remote machine, I want to add 7-8 minutes to it and print it in the same format like 1641960817177.
Couldn't find similar post
CodePudding user response:
Since you are relying on an application to deliver the time, you probably need to parse it before adding the time. Something like
precision rfc3339 |
# parse the number out
Select-String -Pattern '\d ' |
Select-Object -ExpandProperty Matches |
# retrieves just the number
Select-Object -ExpandProperty Value |
# adds 8 minutes (*60seconds)
# order is important so that it converts the string into a number type
ForEach-Object {60*8 $_}
Or, if that looks daunting there technically is a non-pipeline approach:
$(precision rfc3339) -Match '\d '
60*8 $Matches[1]
Personally, although it looks a bit more convoluted, I think PowerShell is the strongest when using its pipelines, but that is a matter of style/choice.
