| Author |
How to get java Date with Daylight savings
|
Santoshkumar Jeevan Pawar
Greenhorn
Joined: Aug 19, 2006
Posts: 27
|
|
Hello,
If i apply daylight savings and e.g selects PST then java new Date() returns wrong time and date.
So how can i fix this issue and get date with applying daylight savings.
E.g. System.out.println( new Date()); gives me 03:19 AM but current time is 04:19.
Your help will be really appreciated.
Thank You.
Have a Nice Time.
-Santosh
|
 |
shivendra tripathi
Ranch Hand
Joined: Aug 26, 2008
Posts: 263
|
|
|
You should be using java calender API, where you can set time zone you want with day light saving. When you print Date it takes default time zone of JVM and print date accordingly.
|
SCJP 1.5(97%) My Blog
|
 |
Santoshkumar Jeevan Pawar
Greenhorn
Joined: Aug 19, 2006
Posts: 27
|
|
|
Can you please give me block of code to print current time with daylight savings
|
 |
shivendra tripathi
Ranch Hand
Joined: Aug 26, 2008
Posts: 263
|
|
You might find this link useful.
http://www.javakb.com/Uwe/Forum.aspx/java-programmer/43489/Daylight-Savings-Time-in-Calendar
|
 |
Varun Chopra
Ranch Hand
Joined: Jul 10, 2008
Posts: 204
|
|
Try this code:
|
-Varun -
(My Blog) - Mock Tests
|
 |
Santoshkumar Jeevan Pawar
Greenhorn
Joined: Aug 19, 2006
Posts: 27
|
|
Hello,
Thanks for your efforts.
Here is solution,
GregorianCalendar gc = new GregorianCalendar();
TimeZone tz = gc.getTimeZone();
gc.add(GregorianCalendar.MILLISECOND, +tz.getDSTSavings());
System.out.println(gc.getTime());
Thank You.
Have a Nice Time.
-Santosh
|
 |
 |
|
|
subject: How to get java Date with Daylight savings
|
|
|