In the below code, i m trying to get dateformat for timezone PST, but i didnt get the expected output. But, If I uncomment the 2 lines (setDefault timezone), i m getting the expected results.
Do you have any good option?
System.out.println("TimeZone.getDefault():"+TimeZone.getDefault()); // CST
//TimeZone.setDefault(TimeZone.getTimeZone("PST"));
Calendar cal = java.util.Calendar.getInstance(SimpleTimeZone.getTimeZone("PST"));
//Calendar cal = java.util.Calendar.getInstance();
Date c = cal.getTime();
String out = new java.text.SimpleDateFormat("MMMMMddyyyy").format(c);
System.out.println("out:"+out);
If the current date in CST is February082015 (at night 12 to 2 AM), then the expected output for PST would be February072015 (PST is 2hrs behind CST). But, I m getting the output as February082015.