Foren

java.util.Date showing wrong current date

thumbnail
prathyush kp, geändert vor 15 Jahren.

java.util.Date showing wrong current date

New Member Beiträge: 11 Beitrittsdatum: 14.01.09 Neueste Beiträge
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, geändert vor 15 Jahren.

RE: java.util.Date showing wrong current date

Junior Member Beiträge: 71 Beitrittsdatum: 23.03.07 Neueste Beiträge
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, geändert vor 15 Jahren.

RE: java.util.Date showing wrong current date

New Member Beiträge: 11 Beitrittsdatum: 14.01.09 Neueste Beiträge
But That too is not workin for me
thumbnail
prathyush kp, geändert vor 15 Jahren.

RE: java.util.Date showing wrong current date

New Member Beiträge: 11 Beitrittsdatum: 14.01.09 Neueste Beiträge
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, geändert vor 15 Jahren.

RE: java.util.Date showing wrong current date

Junior Member Beiträge: 71 Beitrittsdatum: 23.03.07 Neueste Beiträge
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, geändert vor 15 Jahren.

RE: java.util.Date showing wrong current date

New Member Beiträge: 11 Beitrittsdatum: 14.01.09 Neueste Beiträge
Thanks tobias .... Its working fine now. Thank you very much
Sana Afreen Yadgir, geändert vor 11 Jahren.

RE: java.util.Date showing wrong current date

New Member Beiträge: 4 Beitrittsdatum: 09.05.12 Neueste Beiträge
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, geändert vor 11 Jahren.

RE: java.util.Date showing wrong current date

Liferay Legend Beiträge: 14914 Beitrittsdatum: 02.09.06 Neueste Beiträge
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, geändert vor 11 Jahren.

RE: java.util.Date showing wrong current date

New Member Beiträge: 4 Beitrittsdatum: 09.05.12 Neueste Beiträge
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