on 09-29-2005 7:39 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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;)
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.