cancel
Showing results for 
Search instead for 
Did you mean: 

Changing the Time Zone attribute

Former Member
0 Kudos

Hi,

I have an application where the current date and time is displayed on the view.

I have used the following lines of code to implement this.

String date_time = Calendar.getInstance().getTime().toString();

wdContext.currentContextElement().setDate_time(date_time);

This returns a value where the time zone is displayed in GMT i.e

Thu Sep 29 11:55:39 GMT+05:30 2005

But I need to display the time in CDT.

Can anyone let me know how we can achieve this?

Thanks in advance,

Reena

Accepted Solutions (1)

Accepted Solutions (1)

achim_hauck2
Active Contributor
0 Kudos

is CDT = "CENTRAL DAYLIGHT SAVING TIME", that means GMT-5?

anyway, you can specify your TimeZone before you use the getTime() like this:


TimeZone myTZ = TimeZone.getTimeZone("GMT-5");
DateFormat df = DateFormat.getDateTimeInstance();
df.setTimeZone(myTZ);
String date_time = df.format(Calendar.getInstance().getTime());

kr, achim

Former Member
0 Kudos

Hi Achim,

Thanks for the reply.

Yes, CDT - Central Daylight Saving TIme = GMT - 5

I tried the code you have given. But it gives me the following error.

java.lang.IllegalArgumentException: Cannot format given Object as a Date

at java.text.DateFormat.format(DateFormat.java:279)

at java.text.Format.format(Format.java:133)

at com.sap.bp.reena.PRListView.wdDoInit(PRListView.java:114)

at com.sap.bp.reena.wdp.InternalPRListView.wdDoInit(InternalPRListView.java:160)

at com.sap.tc.webdynpro.progmodel.generation.DelegatingView.doInit(DelegatingView.java:61)

at com.sap.tc.webdynpro.progmodel.controller.Controller.initController(Controller.java:215)

at com.sap.tc.webdynpro.progmodel.view.View.initController(View.java:274)

at com.sap.tc.webdynpro.progmodel.controller.Controller.init(Controller.java:200)

at com.sap.tc.webdynpro.progmodel.view.ViewManager.getView(ViewManager.java:540)

at com.sap.tc.webdynpro.progmodel.view.ViewManager.bindRoot(ViewManager.java:422)

at com.sap.tc.webdynpro.progmodel.view.ViewManager.init(ViewManager.java:130)

Any idea where I'm going wrong?

Regards

Reena

achim_hauck2
Active Contributor
0 Kudos

the code works fine.

it just gaves me the outut:

29.09.2005 06:00:48

which object do you pass to the df.format method?

did you copy & paste the code?

any missspellings probably?

do you use the correct classes? (look for the imports:

import java.text.DateFormat;

import java.util.Calendar;

import java.util.TimeZone;)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Reena,

the time displayed in your example is actually not GMT but the server's default timezone +5:30 is India, right?

Achim's Code should do the job, though I recommend you use CDT directly or something like

String tz=TimeZone.getTimeZone("America/Chicago"

to get the time zone. This should take care of daylight savings time as well, while GMT-5 couldn't.

Thanks

Bruno

Former Member
0 Kudos

Hi,

I tried running the same code again today and its working absolutely fine!

Though I made no changes to the code!

Anyway, thanks Achim and Bruno for the help.

Regards

Reena