File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes How to get java Date with Daylight savings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to get java Date with Daylight savings" Watch "How to get java Date with Daylight savings" New topic
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: 211
Try this code:



-Varun -
(My Blog) - Online Certifications - Webner Solutions
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
 
Similar Threads
HELP: Daylight Savings in Java
obtain historical DSt transitions times
java timezones
Java6 gives wrong file timestamp during daylight savings on windows
Daylight Saving TIme off by 1 Hour