Fórum

java.util.Date showing wrong current date

thumbnail
prathyush kp, modificado 15 Anos atrás.

java.util.Date showing wrong current date

New Member Postagens: 11 Data de Entrada: 14/01/09 Postagens Recentes
Hi all

I Am not able to get current date by using java.util.Date.

I have set the user.timezone in system.properties as IST(Indian standard Time). Also -Duser.timezone=IST in setenv.bat

But java.util.Date still showing a 5.30 hour lagging. I thing it is still taking GMT only

Am using liferay 5.1.2 and windows machine

Plz help me its urgent
thumbnail
Tobias Gindler, modificado 15 Anos atrás.

RE: java.util.Date showing wrong current date

Junior Member Postagens: 71 Data de Entrada: 23/03/07 Postagens Recentes
Hello,

Use the java.util.Calendar class. It will help you.
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Calendar.html

Best regards

Tobias
thumbnail
prathyush kp, modificado 15 Anos atrás.

RE: java.util.Date showing wrong current date

New Member Postagens: 11 Data de Entrada: 14/01/09 Postagens Recentes
But That too is not workin for me
thumbnail
prathyush kp, modificado 15 Anos atrás.

RE: java.util.Date showing wrong current date

New Member Postagens: 11 Data de Entrada: 14/01/09 Postagens Recentes
Bez date current Date is wrong its effecting Quatz shedular also

Plz help me to get Current date and time in IST(Not GST)
thumbnail
Tobias Gindler, modificado 15 Anos atrás.

RE: java.util.Date showing wrong current date

Junior Member Postagens: 71 Data de Entrada: 23/03/07 Postagens Recentes
Hi,

use the following:
Calendar vCalendar = Calendar.getInstance(TimeZone.getTimeZone("Asia/Calcutta"));
System.out.println(vCalendar.toString());


The Calendar instance will store the date in IST correctly.
Use the Calendar.get(int field) function to access the day,month,year,... directly.
You can use the java.text.DateFormat with the calendar instance to generate a formatted String.

Don't use the Date class at all, because it is more or less deprecated.

Best regards

Tobias
thumbnail
prathyush kp, modificado 15 Anos atrás.

RE: java.util.Date showing wrong current date

New Member Postagens: 11 Data de Entrada: 14/01/09 Postagens Recentes
Thanks tobias .... Its working fine now. Thank you very much
Sana Afreen Yadgir, modificado 11 Anos atrás.

RE: java.util.Date showing wrong current date

New Member Postagens: 4 Data de Entrada: 09/05/12 Postagens Recentes
Hello,
I have resloved this problem by setenv.bat. The tomcat bundle provided by Liferay contains the setenv.bat inside the bin folder of tomcat.
modified the timezone inside the setenv.bat as
-Duser.timezone=Asia/Calcutta
thumbnail
David H Nebinger, modificado 11 Anos atrás.

RE: java.util.Date showing wrong current date

Liferay Legend Postagens: 14919 Data de Entrada: 02/09/06 Postagens Recentes
This is the wrong way to do it.

After logging in you should go to the settings control panel to display settings and set the timezone to use.

Liferay works best running under UTC as it transforms all times from the various possible user timezones to UTC for storage, then converts back to the viewing user's timezone for display.

Setting it in the JAVA_OPTS that way breaks this automated conversion mechanism.
Sana Afreen Yadgir, modificado 11 Anos atrás.

RE: java.util.Date showing wrong current date

New Member Postagens: 4 Data de Entrada: 09/05/12 Postagens Recentes
Hi,
I tried like this also but It was not working.I followed above steps still tomcat server shows same time.That's y I did by setevn.bat file.It's working fine.
Regards,
Sana