A DESCRIPTION OF THE REQUEST :
I was trying to return a Date object instead of String after parsing the date of another timezone.
Like the server is in EST zone and i want to know what is the time in PST and compare the dates in my app.
But when i parse the string to get the DATE, it is giving me again in same EST istead of PST
========================================================
Here is the sample code:
TimeZone tz = TimeZone.getTimeZone("PST");
Date now = new Date();
DateFormat df = new SimpleDateFormat ("EEE MMM dd HH:mm:ss z yyyy");
df.setTimeZone(tz);
String currentTime = df.format(now);
//do not parse the timezones date and time,
//because it will go to DEFAULT timezone.
//Still try for the output
Date cDate = df.parse(currentTime,p);
System.out.println("The Current Time in PST: "+currentTime);
System.out.println("The "+ tz.getDisplayName()+" : "+cDate);
=======================================================
here since the current time is parsed, it is giving me the EST time as i am testing this on my EST timezone computer.
I see in JAVA J2EE API v1.4 the Format method in SimpleDateFormat returns only String not Date.
I am requesting to add some more methods in SimpleDateFormat class or DateFormat class which can return DATE along with String (which right now is returning String only)
JUSTIFICATION :
I am requesting to add some more methods in SimpleDateFormat class or DateFormat class which can return DATE along with String (which right now is returning String only)
This is required because i am working on application which calculates TAX on one of my application. This application will be used even by CALIFORNIA taxpayers also but the application is developed in NY on EST and the server is also located in EST zone only.
So when taxpayer of CA login to file tax return at night 9PM in PST , it is already the next day in EST and 12AM in hours. Then, we need to imply penalty and interest on his return which is not correct according to Federal law.
I need to compare the PST date and Time with Due Date (which is date object) in my application to avoid penalty and interest. But JAVA code is not letting me to do this.
I see in JAVA J2EE API v1.4 the Format method in SimpleDateFormat returns only String not Date.
Please, fix this and let me know on my email: ###@###.###
It you already have solution, please mail me how to fix and sample code for it.
I appreciate your help.
---------- BEGIN SOURCE ----------
TimeZone tz = TimeZone.getTimeZone("PST");
Date now = new Date();
DateFormat df = new SimpleDateFormat ("EEE MMM dd HH:mm:ss z yyyy");
df.setTimeZone(tz);
//I want this df.format ==> to return Date instead of String
String currentTime = df.format(now);
//This parse method change the date from PST to EST date and Time
Date cDate = df.parse(currentTime,p);
System.out.println("The Current Time in PST: "+currentTime);
System.out.println("The "+ tz.getDisplayName()+" : "+cDate);
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
I am doing as a temporary fix to my code as:
public Date getDateOnTimeZone(String zone)
{
Date now = new Date();
TimeZone currentTimeZone = TimeZone.getTimeZone(zone);
// or PST, MID, etc ...
DateFormat df = new SimpleDateFormat ("yyyy-MM-dd hh:mm:ss");
df.setTimeZone(currentTimeZone);
String currentDateTime = df.format(now);
// I am doing substring on the PST date and setting the date and hour
// to Date function. But i see these functions are deprecated........
int dateEndIndex = currentDateTime.indexOf(" ");
int timeEndIndex = currentDateTime.indexOf(":");
now.setDate(Integer.parseInt(currentDateTime.substring((dateEndIndex-2), dateEndIndex)));
now.setHours(Integer.parseInt(currentDateTime.substring((timeEndIndex-2), timeEndIndex)));
return now;
}
###@###.### 2005-2-18 06:07:07 GMT