-
SimpleDateFormat
I would like to parse and format date string which i get from database to
extract only the time.
dateTime = "September 22, 2000 2:43 PM EDT"; (from database)
String timeStr = "";
try{
SimpleDateFormat givenFormat = new SimpleDateFormat("MMMM dd,
yyyy hh:mm a zzz");
Date givenDate = givenFormat.parse(dateTime, new ParsePosition(0));
SimpleDateFormat timeFormat = new SimpleDateFormat("hh:mm a zzz");
timeStr = timeFormat.format(givenDate);
}catch(Exception ex)
{
timeStr = dateTime;
}
This method gives the output as
"11:43 AM PDT"
instead of "2:43 PM EDT"
The parse method returns the date object with reference to my machines date
time setting. But i wanted the time and timezone as such.
Can any one help me to fix this.
Thanks,
Jeeva.
-
Re: SimpleDateFormat
I've just had the same problem with date formats, my times were 8 hours out
due to them being set in Pacific time. To get around this I've just been
using
myDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
Problem is my program needs to be localised and hardcoding "GMT" is not a
solution.
So I'd like to know if you or anyone reading this knows how to reference
your system's timezone son that this can be used instead??
Regards
Trish
"Jeeva" <jvelumani@etrade.com> wrote:
>
>I would like to parse and format date string which i get from database to
>extract only the time.
>
> dateTime = "September 22, 2000 2:43 PM EDT"; (from database)
> String timeStr = "";
> try{
> SimpleDateFormat givenFormat = new SimpleDateFormat("MMMM dd,
>yyyy hh:mm a zzz");
> Date givenDate = givenFormat.parse(dateTime, new ParsePosition(0));
> SimpleDateFormat timeFormat = new SimpleDateFormat("hh:mm a zzz");
> timeStr = timeFormat.format(givenDate);
> }catch(Exception ex)
> {
> timeStr = dateTime;
> }
>
>This method gives the output as
>"11:43 AM PDT"
>instead of "2:43 PM EDT"
>
>The parse method returns the date object with reference to my machines date
>time setting. But i wanted the time and timezone as such.
>
>Can any one help me to fix this.
>Thanks,
>Jeeva.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks