SimpleDateFormat problem parsing timezone

View: New views
2 Messages — Rating Filter:   Alert me  

SimpleDateFormat problem parsing timezone

by anja :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I've written some code that should parse some date information like this:

- "2007-4-27 6:54:0 PST"
- "2007-4-27 6:54:0 EDT"

The code looks like this:

  UErrorCode status(U_ZERO_ERROR);
  static const icu::UnicodeString pattern("yyyy-MM-dd HH:mm:ss zzz", -1, US_INV);
  icu::SimpleDateFormat date_format(
      pattern,
      status);
  const icu::TimeZone* timezone = icu::TimeZone::createTimeZone("PST");
  date_format.setTimeZone(*timezone);
  UDate date = date_format.parse(i18n::Utf16FromUtf8(value),
                                 status);

It works fine for timezones given in PST, but if the timezone information is EDT an error gets reported by U_FAILURE(status).

Any idea how the code has to be changed to support both timezones?

Thanks,
Anja
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
icu-support mailing list - icu-support@...
To Un/Subscribe: https://lists.sourceforge.net/lists/listinfo/icu-support

Re: SimpleDateFormat problem parsing timezone

by Mark Davis-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
 

On 5/3/07, Anja Hauth <anja.hauth@...> wrote:
Hi,

I've written some code that should parse some date information like this:

- "2007-4-27 6:54:0 PST"
- "2007-4-27 6:54:0 EDT"

The code looks like this:

  UErrorCode status(U_ZERO_ERROR);
  static const icu::UnicodeString pattern("yyyy-MM-dd HH:mm:ss zzz", -1, US_INV);
  icu::SimpleDateFormat date_format(
      pattern,
      status);
  const icu::TimeZone* timezone = icu::TimeZone::createTimeZone("PST");
  date_format.setTimeZone(*timezone);
  UDate date = date_format.parse(i18n::Utf16FromUtf8(value),
                                 status);

It works fine for timezones given in PST, but if the timezone information is EDT an error gets reported by U_FAILURE(status).

Any idea how the code has to be changed to support both timezones?

Thanks,
Anja
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
icu-support mailing list - icu-support@...
To Un/Subscribe: https://lists.sourceforge.net/lists/listinfo/icu-support




--
Mark
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
icu-support mailing list - icu-support@...
To Un/Subscribe: https://lists.sourceforge.net/lists/listinfo/icu-support