How to use tzupdater tool for linux and unix


At this post, I describe how to use tzupdater to update tzdata for JAVA. All steps performed on HP-UX  11.31  server.

Step 1:Download and  Extract File

Extract Fıle tzdata2016g.tar.gz . You can get it from the link which I added below.

IANA

Also, you need tzupdater for your OS version.I added some of them but you should check "google" for more details.

HP-UX:

TzUpdater:

Step 2:Edit Version 

Extract  tzdata201g file and edit MakeFile for a version update.
 

#vi MakeFile
From.;
VERSION= unknown
to;
VERSION= 2016g


Step 3:Compress New Tzdata 

Compress fixed MafeFile version with the same name.

#tar -cvf tzdata2016g.tar /tmp/new_tzdata2016g/*

Step 4:Create SHA12 

I used the Linux server which sha12sum package installed. This command will create a sha12 key for your compressed file.
 

#sha512sum /tmp/tzdata2016g.tar.gz

Step 5:Create sha512 file.

Copy sha12sum command output and paste it to "tzdata2016g.tar.gz.sha512"
 

# sha512sum /tmp/tzdata2016g.tar.gz |awk '{print $1}' > /tmp/tzdata2016g.tar.gz.sha512


Step 6:File Extraction

Extract "tzupdater" binary ; then copy "tzdata2016g.tar.gz" file in this directory. Also tzdata2016g.tar.gz.sha512 must be in the same directory.

#tar -xvf tzupdater-2.0.0.tar

Step 7:Apply and test tzupdater.Java path can be changed with your installation directory.

#cd /tmp/tzupdater-2.0.0
#/opt/java6/bin/IA64N/java -jar tzupdater.jar --verbose -l file:///tmp/tzupdater-2.0.0/tzdata2016g.tar.gz
java.home: /opt/java6/jre
java.vendor: Hewlett-Packard Co.
java.version: 1.6.0.16
Downloaded file to /var/tmp/tz.tmp/tzdata.tar.gz
JRE tzdata version: tzdatatzdata2016g
tzupdater tool would update with tzdata version: tzdata2016g
Embedded tzmappings data version: tzdata2016g
Downloaded file to /var/tmp/tz.tmp/sha512hash
Current JRE has later version ({0}) than the tzupdater provided one ({1}).
The tzmappings file requires update
Updating tzmappings file... done.
Renaming tzmappings file... done.
done.
Extracting files... done.
Renaming /opt/java6/jre/lib/zi to /opt/java6/jre/lib/zi.tzdatatzdata2016g
Renaming /opt/java6/jre/lib/zi.tzdata2016g to /opt/java6/jre/lib/zi
Validating for : tzdata2016g
Validation complete
JRE updated to version : tzdata2016g

Step 8:Check new timezone

root @ TEST# /opt/java6/bin/IA64N/java GetCurrentDateTimeZone
2016/10/30 03:59:59 GMT+03:00
root @ TEST# /opt/java6/bin/IA64N/java GetCurrentDateTimeZone
2016/10/30 04:00:00 GMT+03:00

You can use this script to check  Java Timezone  information. The firstscript gets default Timezone information and the second one gets all supported timezones. You need to compile them with  JAVAC command. JAVAC  can be found under  JDK  binary.

#javac  TimeZoneExample.java
#javac  GetCurrentDateTimeZone.java

Then  This command creates  GetCurrentDateTimeZone.class  and  TimeZoneExample.class  file. You need to run  this  command  like a added to get  information.

#java  TimeZoneExample | grep  Istanbul
#java  GetCurrentDateTimeZone
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;

public class TimeZoneExample {

public static void main(String[] args) {

String[] ids = TimeZone.getAvailableIDs();
for (String id : ids) {
System.out.println(displayTimeZone(TimeZone.getTimeZone(id)));
}

System.out.println("\nTotal TimeZone ID " + ids.length);

}

private static String displayTimeZone(TimeZone tz) {

long hours = TimeUnit.MILLISECONDS.toHours(tz.getRawOffset());
long minutes = TimeUnit.MILLISECONDS.toMinutes(tz.getRawOffset())
- TimeUnit.HOURS.toMinutes(hours);
// avoid -4:-30 issue
minutes = Math.abs(minutes);

String result = "";
if (hours > 0) {
result = String.format("(GMT+%d:%02d) %s", hours, minutes, tz.getID());
} else {
result = String.format("(GMT%d:%02d) %s", hours, minutes, tz.getID());
}

return result;

}

}

Get Default Timezone  Information


 

import java.util.Calendar;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

public class GetCurrentDateTimeZone {
public static void main(String[] args) {
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss z");
Calendar cal = Calendar.getInstance();
System.out.println(dateFormat.format(cal.getTime()));
}
}

 

Tagged In:

I'm a IT Infrastructure and Operations Architect with extensive experience and administration skills and works for Turk Telekom. I provide hardware and software support for the IT Infrastructure and Operations tasks.

205 Total Posts
Follow Me

Related Post