cancel
Showing results for 
Search instead for 
Did you mean: 

how to convert CCtDateTime.TimeZoneCode into Java understandable time zone

pradeep_kumar1
Employee
Employee
0 Kudos

Hi ,

I have a problme getting the correct formate of time zone (which is understandable by java ) from the timezonecode i get from CCtDate Time.

Can somebody help me.

Regards,

Pradeep

Accepted Solutions (1)

Accepted Solutions (1)

pradeep_kumar1
Employee
Employee
0 Kudos

Hi Babu and other who may intersted,

I got a simple and sweet way of doing this , which is exactly i was looking for.

We can use the class "SAPTimeZone' which is defined under the package 'com.sap.i18n.timezone'

And the method 'getIdJavafromAbap(<abap code>)' can be used to get the valid java code from ABAP timezone code.

Here is the sample snippet:

SimpleDateFormat isoTZIFormatter = new SimpleDateFormat(

"yyyy-MM-dd'T'HH:mm:ss");

CctDateTime localDateTimeStart = (CctDateTime) barElement

.getAttributeValue("StartDate$LocalNormalisedDateTime");

isoTZIFormatter.setTimeZone(TimeZone.getTimeZone(SAPTimeZone.getIdJavaFromAbap(localDateTimeStart

.getTimeZoneCode().getContent())));

In simple form:

isoTZIFormatter.setTimeZone(TimeZone.getTimeZone(SAPTimeZone.getIdJavaFromAbap("UTC+53")

Courtesy B, Himabindu ( I035784).

Thanks and Regards,

Pradeep

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

I didnt get what exactly u want,

but u can try with

DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");

formatter.setLenient(false);

and also GregorianCalendar gc = new GregorianCalendar(1900, Calendar.JANUARY,1);

Classes of java.

please post clearly what input u r getting and u want to extract to

Babu

pradeep_kumar1
Employee
Employee
0 Kudos

Hi Babu,

May be I was not clear enough . The code goes like this

CctCode timeZoneCode = dateTime.getTimeZoneCode();

Basically this is a CctCode and this will give me the timeZoneCode as "CET" , UTC+53"....

now I have to create an instance of Gregorian calendar with the time zone code above i got.

But problem here is that constructure of Gregorain calendar need TImeZone Object.

Greagorian Calendar gc = new GregorianCalendar ( Time Zone );

How Can i create object object Time Zone from time zone code.

The main problem here the different representation of Time Zone in ABAP and JAVA.

if you notice the typical way to create a TimeZone object in JAVA is

TimeZone TZ = TimeZone.getTimeZone("Europe/Berlin");

I hope now the problem is clear. Please let me know if still

Regards,

Pradeep

Former Member
0 Kudos

Hi,

Here is the code u asked for...

Here i am trying to create a GregorianCalendar from timezone.

TimeZone tz = TimeZone.getTimeZone(TimeZoneIds<i>) will create a timezone object from the TimeZoneId's.

Some part of code actually nt required... but for understanding purpose i have written...

import java.util.Date;

import java.util.GregorianCalendar;

import java.util.TimeZone;

public class sdn_datetest {

public sdn_datetest() {

}

public static void main(String a[]) {

Date date = new Date();

String TimeZoneIds[] = TimeZone.getAvailableIDs();

for(int i=0;i<TimeZoneIds.length;i++)

{

TimeZone tz = TimeZone.getTimeZone(TimeZoneIds<i>);

String temp = tz.getDisplayName(tz.inDaylightTime(date),TimeZone.LONG);

//System.out.print(tz.getDisplayName(tz.inDaylightTime(date),TimeZone.LONG));

int off = tz.getRawOffset();

int hour = off / (60601000);

int minute = Math.abs(off / (60*1000)) % 60;

System.out.println(off);

System.out.println( " " + hour + ":" + minute);

GregorianCalendar gc = new GregorianCalendar(tz);

System.out.println("Time\t"+gc.getTime());

}

}

}

If still nt solved... do post

Babu