
Sample Code
String timestamp1 = "Wed Mar 02 00:00:54 PST 2011"; Date d = new Date(timestamp1); System.out.println(d.toString()); String timestamp2 = "Wed Mar 02 12:57:52 IST 2011"; Date d2 = new Date(timestamp2); System.out.println(d2.toString());
The date object is not getting created for IST time zone. Java is throwing an Illegal Argument Exception Why is the second SOP always throwing an exception ? This piece of code is running on app servers on machines in different time zones ? How do I always make sure that the date gets created in a particular time zone ?

The toString() method already displaying IST by default.
Modified your code:
import java.util.*;
class Example
{
public static void main(String[] args)
{
String timestamp1 = "Wed Mar 02 00:00:54 2011";
Date d = new Date(timestamp1);
System.out.println(d.toString());
String timestamp2 = "Wed Mar 02 12:57:52 2011";
Date d2 = new Date(timestamp2);
System.out.println(d2.toString());
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.