Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Archives of Support Questions (Read Only)

This is an archived board for historical reference. Information and links may no longer be available or relevant
Announcements
This board is archived and read-only for historical reference. To ask a new question, please post a new topic on the appropriate active board.

Convert millseconds into Unix TimeStamp

avatar
New Member

Hi experts, I've the following field: 1388481000000 as the number of milliseconds elapsed from the Unix Epoch (1970-01-01 UTC) How can I convert to Unix TimeStamp? I'm trying to use ToUnixTime(1388481000000,'dd/MM/yyyyHH:mm:ss','GMT') but it gives me error... How can I convert into Unix Timestamp? Many thanks!

1 ACCEPTED SOLUTION

avatar
Super Collaborator

Hi @Johnny Fugers,

Input file data as: dataset.csv

This gives answer in CET

563355,1388481000000

563355,1388481000000

563355,1388481000000

563356,1388481000000

a = load '/tmp/dataset.csv' using PigStorage(',') as (id:chararray, at:chararray);

b = foreach a generate id, ToString( ToDate( (long)at), 'yyyy-MM-dd hh:ss:mm' );

c = group b by id;

dump c;

5982-screen-shot-2016-07-21-at-41545-pm.png

This is how it works in GMT:

a = load '/tmp/dataset.csv' using PigStorage(',') as (id:chararray, at:chararray);

b = foreach a generate id, ToDate(ToString(ToDate((long) at), 'yyyy-MM-dd hh:ss:mm'), 'yyyy-MM-dd hh:ss:mm', 'GMT');

c = group b by id;

dump c;

5983-screen-shot-2016-07-21-at-42735-pm.png

Hope that helps,

Thanks,

Sujitha

View solution in original post

1 REPLY 1

avatar
Super Collaborator

Hi @Johnny Fugers,

Input file data as: dataset.csv

This gives answer in CET

563355,1388481000000

563355,1388481000000

563355,1388481000000

563356,1388481000000

a = load '/tmp/dataset.csv' using PigStorage(',') as (id:chararray, at:chararray);

b = foreach a generate id, ToString( ToDate( (long)at), 'yyyy-MM-dd hh:ss:mm' );

c = group b by id;

dump c;

5982-screen-shot-2016-07-21-at-41545-pm.png

This is how it works in GMT:

a = load '/tmp/dataset.csv' using PigStorage(',') as (id:chararray, at:chararray);

b = foreach a generate id, ToDate(ToString(ToDate((long) at), 'yyyy-MM-dd hh:ss:mm'), 'yyyy-MM-dd hh:ss:mm', 'GMT');

c = group b by id;

dump c;

5983-screen-shot-2016-07-21-at-42735-pm.png

Hope that helps,

Thanks,

Sujitha