Apache PIG - Convert millseconds into TimeStamp Unix - hadoop

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!

You are mixing things up.ToUnixTime syntax is ToUnixTime(datetime) where the parameter is a datetime object.What you have is the milliseconds elapsed from the Unix epoch (1970-01-01 UTC).I assume you are trying to convert the milliseconds to a datetime object for which you will have to use ToDate and the syntax is ToDate(milliseconds).
ToDate(1388481000000)

Related

Parse Unix timestamp with offset in php example timestamp 1671847200000-0600

I am trying to parse the Unix timestamp in Laravel
/Date(1671847200000-0600)/
where 1671847200000 is the timestamp and this is -0600 offset (-06:00 i.e. -HH::mm)
expected output be like
2022-12-23 18:00:00

I want to get local time in shell script in the specified format HH:MM:SS

I want to get startTime as start of current time (for eg current time is 12:55 pm) then startTime will be 12:00:00 and endTime will be 12:59:59.
I tried using startTime="$(date +'%H:%M:%S')" but this is giving time according to UTC time format i.e: 07:25:43. But I want result according to my local time zone. Zone is '+0530'.
You need to export the TZ before you run date like:
export TZ=Asia/Kolkata
startTime="$(date +'%H:%M:%S')"
or in one line:
startTime="$(TZ=Asia/Kolkata date +'%H:%M:%S')"

How to convert unix timestamp to formatted date in ruby?

I'm struggling with ruby date api. I need to convert a timestamp number to formatted date. But when i use:
Time.at(1517486994710).to_datetime
or
DateTime.strptime("1517486994710",'%s')
(1517486994710 is unix timestamp for today), i see 50057 year as output. What i'm doing wrong?
You have the epoch with milliseconds. Use %Q formatter:
DateTime.strptime("1517486994710",'%Q')
#⇒ Thu, 01 Feb 2018 12:09:54 +0000
Your script is correct but your epoch is incorrect. Today epoch is 1517491785.
You probably got the js epoch which counts in milliseconds
DateTime.strptime("1517486994",'%s') # removed 710

Converting timestamp with time zone to local time in Bash

I am trying to do basic time math in Bash having following timestamps from OpenDj:
createtimestamp: 20161123165725Z
I don't know what time zone the system will be set with, it can be with "Zulu" timezone (UTC) as above, or might be with some other timezone. The above timestamp is for the users on LDAP servers. What I need to do is to compare the timestamp of the user with a certain timestamp.
Question: how do I convert the timestamp with zone (Z) above to local timestamp or epoch time in Bash?
Maybe Dateutils will help
http://www.fresse.org/dateutils/
dateconv -i '%s' -f '%A, %d %b %Y' 1234567890
Friday, 13 Feb 2009
dateutils tools default to UTC (add -z your/timezone if needed).

How to get diff between utc time and localtime in seconds?

How to get in bash diff between utc time and localtime in seconds ?
%s isn't trivially part of the answer without some time-related antics, epoch seconds is explicitly UTC (or maybe GMT if you're old-school), so setting TZ won't affect it.
Similar to twalberg's suggestion:
IFS=":" read hh mm < <(date +%:z)
echo $(($hh*3600+$mm*60))
You can test that this is doing what you want by setting TZ for the date command:
IFS=":" read hh mm < <(TZ=Australia/Sydney date %:z) # answer is 39600
IFS=":" read hh mm < <(TZ=US/Eastern date +%:z) # answer is -18000
(This isn't strictly a bash answer, since it requires GNU date or equivalent, 5.90 and later support %:z and %::z)
You'll probably have to do a little work to get it in seconds, but date +%z will report your configured timezone offset as [+-]HHMM. Parse the output of that and do the appropriate math to figure it out in seconds.
This will only work in places with whole hours and not minutes.
echo $(($( date +%z)*36))

Resources