17.10 - Example: Getting and Setting the Time Zone in a Java Table Operator - Advanced SQL Engine - Teradata Database

Teradata Vantageā„¢ - SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Release Date
July 2021
Content Type
Programming Reference
Publication ID
B035-1147-171K
Language
English (United States)

The following code excerpt shows the usage of the Java TeradataTime and TeradataTimestamp data types and the getTimeZone and setTimeZone methods for getting and setting the time zone value in a Java table operator.

String timezone = "America/New_York";
Calendar c = Calendar.getInstance();
TimeZone tz = TimeZone.getTimeZone(timezone);
c.setTimeZone(tz);

TeradataTimestamp tts = new TeradataTimestamp( c.getTimeInMillis());
tts.setTimeZone(tz);

TeradataTime tTime = new TeradataTime(c.getTimeInMillis());
tTime.setTimeZone(tz);

   if(outObjs[i] instanceof TeradataTimestamp){
      TeradataTimestamp outtts = (TeradataTimestamp)outObjs[i];
      java.util.TimeZone tz = outtts.getTimeZone();
   }
   else if(outObjs[i] instanceof TeradataTime){
      TeradataTime outtTime = (TeradataTime)outObjs[i];
      java.util.TimeZone tz = outtTime.getTimeZone();
   }
   else if(outObjs[i] instanceof Time){
      Time outtTime = (Time)outObjs[i];
      printSimpleTimeReading(outtTime);
   }
   else if(outObjs[i] instanceof Timestamp){
      Timestamp outtTime = (Timestamp)outObjs[i];
      printSimpleTimestampReading(outtTime);
   }