aspose 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
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply 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: 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
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: How to get java Date with Daylight savings
 
Similar Threads
java timezones
obtain historical DSt transitions times
Java6 gives wrong file timestamp during daylight savings on windows
Daylight Saving TIme off by 1 Hour
HELP: Daylight Savings in Java