Posts

Showing posts with the label Unix Timestamp

Convert Unix Time With PowerShell

Answer : See Convert a Unix timestamp to a .NET DateTime . You can easily reproduce this in PowerShell. $origin = New-Object -Type DateTime -ArgumentList 1970, 1, 1, 0, 0, 0, 0 $whatIWant = $origin.AddSeconds($unixTime) Function Convert-FromUnixDate ($UnixDate) { [timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds($UnixDate)) } $niceTime = Convert-FromUnixDate $ctime PS C:\> $niceTime Friday, 18 May 2012 8:24:18 p.m. $date = get-date "1/1/1970" $date.AddSeconds($unixTime).ToLocalTime()

Convert Timestamp Datatype Into Unix Timestamp Oracle

Answer : This question is pretty much the inverse of Convert Unixtime to Datetime SQL (Oracle) As Justin Cave says: There are no built-in functions. But it's relatively easy to write one. Since a Unix timestamp is the number of seconds since January 1, 1970 As subtracting one date from another date results in the number of days between them you can do something like: create or replace function date_to_unix_ts( PDate in date ) return number is l_unix_ts number; begin l_unix_ts := ( PDate - date '1970-01-01' ) * 60 * 60 * 24; return l_unix_ts; end; As its in seconds since 1970 the number of fractional seconds is immaterial. You can still call it with a timestamp data-type though... SQL> select date_to_unix_ts(systimestamp) from dual; DATE_TO_UNIX_TS(SYSTIMESTAMP) ----------------------------- 1345801660 In response to your comment, I'm sorry but I don't see that behaviour: SQL> with the_dates as ( 2 select to_date('...

Convert Python Datetime To Timestamp In Milliseconds

Answer : In Python 3 this can be done in 2 steps: Convert timestring to datetime object Multiply the timestamp of the datetime object by 1000 to convert it to milliseconds. For example like this: from datetime import datetime dt_obj = datetime.strptime('20.12.2016 09:38:42,76', '%d.%m.%Y %H:%M:%S,%f') millisec = dt_obj.timestamp() * 1000 print(millisec) Output: 1482223122760.0 strptime accepts your timestring and a format string as input. The timestring (first argument) specifies what you actually want to convert to a datetime object. The format string (second argument) specifies the actual format of the string that you have passed. Here is the explanation of the format specifiers from the official documentation: %d - Day of the month as a zero-padded decimal number. %m - Month as a zero-padded decimal number. %Y - Year with century as a decimal number %H - Hour (24-hour clock) as a zero-padded decimal number. %M - Minute as a ze...