File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get java Date with Daylight savings

 
Santoshkumar Jeevan Pawar
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 263
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Santoshkumar Jeevan Pawar
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please give me block of code to print current time with daylight savings
 
shivendra tripathi
Ranch Hand
Posts: 263
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 211
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this code:

 
Santoshkumar Jeevan Pawar
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic