How to get the current timezone of a hadoop file system

Viewed 455

I want to find out which timezone the hadoop filesystem is in.
More specifically, I want to know which timezone the date returned by hadoop fs -ls command is.

Is there any command/api to retrieve this?

My problem stems from the fact that the date returned by the hadoop fs -stat command is always in UTC (doc link), and I want to convert this time to the hadoop filesystem time so that my calculations are in sync

1 Answers

Since HDFS use just UTC as a simple format (see stat source on github):

 protected final SimpleDateFormat timeFmt;
  {
    timeFmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    timeFmt.setTimeZone(TimeZone.getTimeZone("UTC"));
  }

So you need just convert it using bash or any other script. You can get epoch time by %Y option from stat command. Now you can remove last three digit from epoch and convert it to your local time by date -d.

~$ ./hadoop-3.2.2/bin/hadoop fs -stat %Y /majid3
~$ date -d @1622704617

You can do it in a single bash command (in ubuntu 20)

mydate=`./hadoop-3.2.2/bin/hadoop fs -stat %Y /yourpathtofile` && date -d @$(echo "($mydate + 500)/1000" | bc)
Related