Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In PowerShell, how do I convert DateTime to UNIX time?

In PowerShell, how can I convert string of DateTime to sum of seconds?

like image 408
RRR Avatar asked Nov 16 '10 10:11

RRR


People also ask

How do I convert DateTime in PowerShell?

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!

Are Unix timestamps always UTC?

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.

What is Unix DateTime?

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.


1 Answers

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 
like image 88
ravikanth Avatar answered Sep 21 '22 08:09

ravikanth