Message Boards Message Boards

0
|
3418 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:
GROUPS:

FromUnixTime ?

Posted 9 years ago

Here are 2 ways of converting UnixTime in date objects:

unixTime = Range[100000];

(1) dates = FromUnixTime /@ unixTime;

(2) dates = DateObject /@ Table[{1970, 1, 1, 2, 0, unixTime[[i]]}, {i, Length[unixTime]}];

The first method takes about 3.5 min and the second about 2 sec.

I am wondering then, what's the point in having FromUnixTime[]?

POSTED BY: Sandu Ursu
2 Replies
Posted 9 years ago

Hi, Marco

I used {1970, 1, 1, 2, 0, ~} to adjust for the time zone. Forgot to mention.

POSTED BY: Sandu Ursu

Hi Sandu,

I can reproduce that. Your second command should read:

dates = DateObject /@ Table[{1970, 1, 1, 1, 0, unixTime[[i]]}, {i, Length[unixTime]}];

Difficult to see why the built-in command takes about 100 times longer to evaluate.

Cheers,

Marco

POSTED BY: Marco Thiel
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract