In PowerShell, how can I convert string of DateTime to sum of seconds?
Using ParseExact method of DateTime, take a string as input, DateTime format, and culture-specific format information, and convert string to DateTime. As in the above output, ParseExact converts string DateTime format to dd/MM/yyyy format DateTime. Cool Tip: How to create a multiline string in PowerShell!
Unix timestamps are always based on UTC (otherwise known as GMT). It is illogical to think of a Unix timestamp as being in any particular time zone. Unix timestamps do not account for leap seconds.
In computing, Unix time (also known as Epoch time, Posix time, seconds since the Epoch, Unix timestamp or UNIX Epoch time) is a system for describing a point in time. It is the number of seconds that have elapsed since the Unix epoch, excluding leap seconds. The Unix epoch is 00:00:00 UTC on 1 January 1970.
PS H:\> (New-TimeSpan -Start $date1 -End $date2).TotalSeconds 1289923177.87462
New-TimeSpan can be used to do that. For example,
$date1 = Get-Date -Date "01/01/1970" $date2 = Get-Date (New-TimeSpan -Start $date1 -End $date2).TotalSeconds
Or just use this one line command
(New-TimeSpan -Start (Get-Date "01/01/1970") -End (Get-Date)).TotalSeconds
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With