Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Convert millseconds into Unix TimeStamp

avatar
Contributor

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