3

I'm trying to read the date fields of Firefox places.sqlite datedase using ADO.NET and PowerShell.

Obviously these fields are in Unix time.

I'm looking for a conversion to .Net datetime or string

Edit: I want to bind the datarow to a WPF GridView.

I need either a way to do the conversion within the SQL query or some way while binding the datarows to the grid.

Cœur
  • 37,241
  • 25
  • 195
  • 267
bernd_k
  • 11,558
  • 7
  • 45
  • 64

4 Answers4

9

Something like this should put you on the right path:

[TimeZone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds($unix))
Keith Hill
  • 194,368
  • 42
  • 353
  • 369
  • I accept this answer, because it is the answer to the verbatime question. My problem was a bit different and meanwhile I found the solution – bernd_k Apr 25 '11 at 21:10
3
[timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds(1303743289))
Nicola Cossu
  • 54,599
  • 15
  • 92
  • 98
3
function Convert-UnixTimeToDateTime([int]$UnixTime)
{
    (New-Object DateTime(1970, 1, 1, 0, 0, 0, 0, [DateTimeKind]::Utc)).AddSeconds($UnixTime)
}

This returns an object with the "kind" set to Utc. Then, if you want local time, call the ToLocalTime method on the resulting object.

OldFart
  • 2,411
  • 15
  • 20
2

The working solution to my problem is

SELECT datetime (b.dateAdded / 1000000, 'unixepoch', 'localtime') dateAdded  from moz_bookmarks

BTW it is partly hidden in the the original documentation.

The other part is that you have to find out, that you must divide the integer by 1000000 to get the seconds.

bernd_k
  • 11,558
  • 7
  • 45
  • 64