forked from yubu/psbbix-zabbix-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
epoch-time-convert.ps1
50 lines (46 loc) · 1.46 KB
/
epoch-time-convert.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
Function convertFrom-epoch {
<#
.Synopsis
Convert from epoch time to human
.Description
Convert from epoch time to human
.Example
convertFrom-epoch 1295113860
.Example
convertFrom-epoch 1295113860 | convertTo-epoch
#>
[CmdletBinding()]
param ([Parameter(ValueFromPipeline=$true)]$epochdate)
if (!$psboundparameters.count) {help -ex convertFrom-epoch | Out-String | Remove-EmptyLines; return}
if (("$epochdate").length -gt 10 ) {(Get-Date -Date "01/01/1970").AddMilliseconds($epochdate)}
else {(Get-Date -Date "01/01/1970").AddSeconds($epochdate)}
}
Function convertTo-epoch {
<#
.Synopsis
Convert time to epoch
.Description
Convert time to epoch
.Example
convertTo-epoch (get-date -date "05/24/2015 17:05")
.Example
convertTo-epoch (get-date -date "05/24/2015 17:05") | convertFrom-epoch
.Example
(get-date -date "05/24/2015 17:05") | convertTo-epoch
.Example
get-date | convertTo-epoch
.Example
convertTo-epoch (get-date).ToUniversalTime()
.Example
convertTo-epoch (get-date).ToUniversalTime() | convertFrom-epoch
.Example
convertTo-epoch ((get-date).AddHours(2)
#>
[CmdletBinding()]
param (
[Parameter(ValueFromPipeline=$true)]$date
)
if (!$psboundparameters.count) {help -ex convertTo-epoch | Out-String | Remove-EmptyLines; return}
$date=$date -f "mm/dd/yyyy hh:mm"
(New-TimeSpan -Start (Get-Date -Date "01/01/1970") -End $date).TotalSeconds
}