convert date in different timezones into default timezone

getting Exception in thread "main" java.text.ParseException:

Page 1 of 1

3 Replies - 3536 Views - Last Post: 17 December 2009 - 11:10 PM Rate Topic: -----

#1 cybernaut09  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 01-June 08

convert date in different timezones into default timezone

Post icon  Posted 17 December 2009 - 06:41 AM

I am reading different files and extracting date out of them . But dates are appearing to be from different timezones ( or from different countries ) , hence I am receiving
Exception in thread "main" java.text.ParseException: Unparseable date: " maandag 19 november 2001 5:48"

while parsing String of date to Date Object .

The code I am using is
SimpleDateFormat dateFormat = new SimpleDateFormat(" EEEE dd MMMM yyyy HH:mm");  
		  dateFormat.setTimeZone(TimeZone.getDefault());  
		   date = dateFormat.parse(strDate);


The pattern I am using in the above code is for the date of format "maandag 19 november 2001 5:48" only , but there are other formats also .

Please help with the parsing , so that I can save all the dates in single default timezone .

Is This A Good Question/Topic? 0
  • +

Replies To: convert date in different timezones into default timezone

#2 Paul-  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 61
  • View blog
  • Posts: 260
  • Joined: 11-December 09

Re: convert date in different timezones into default timezone

Posted 17 December 2009 - 08:23 AM

For parsing dates in different languages you can use a locale. Example for dutch:
	public static void main(String arg[]) throws ParseException {
		String strDate = "maandag 19 november 2001 5:48";
		Locale locale = new Locale("nl");
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"EEE d MMM yyyy H:mm", locale);
		dateFormat.setTimeZone(TimeZone.getDefault());
		Date date = dateFormat.parse(strDate);

		System.out.println(date);
	}


If your list contains a mix of languages and time zones, how can you know what is on each line?
Was This Post Helpful? 0
  • +
  • -

#3 cybernaut09  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 01-June 08

Re: convert date in different timezones into default timezone

Posted 17 December 2009 - 09:44 PM

Thanks for the solution.

View PostPaul-, on 17 Dec, 2009 - 07:23 AM, said:

If your list contains a mix of languages and time zones, how can you know what is on each line?


I am catching exception if SimpleDateFormat is not able to parse strdate and in that I am trying with another language ...and so on .
I know it looks stupid but it is what I can think for it right now . Any suggestions ?
Was This Post Helpful? 0
  • +
  • -

#4 cybernaut09  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 01-June 08

Re: convert date in different timezones into default timezone

Posted 17 December 2009 - 11:10 PM

Well, parsing went smooth for dutch . I tried same with other language but they are still giving exception . Like

java.text.ParseException: Unparseable date: " 23 lutego 2000 09:37"

language - Polish , locale - pl (tried with pattern - "dd MMM yyyy HH:mm")

java.text.ParseException: Unparseable date: " woensdag 12 september 2001 17:52"

language - Afrikaans, locale - af (tried with pattern - "EEEE dd MMM yyyy HH:mm")

java.text.ParseException: Unparseable date: " Mi,rcoles, 02 de Febrero de 2000 03:54 p.m."

language - spanish , locale - es

java.text.ParseException: Unparseable date: " Domingo 25 de Noviembre de 2001 08:02"
language - spanish , locale - es

java.text.ParseException: Unparseable date: " ti 2001-08-28 15:01 "
language - ? , locale - ?


Is the error due to difference in pattern ? I think pattern is used to cast the date according to our needs. What am I doing wrong ?

This post has been edited by cybernaut09: 17 December 2009 - 11:18 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1