Coverting RFC 3339 DateTime Objects in Android returned from Google Tasks API to String
===

I am using the Google Tasks API to return values, such as task title, task note, and task due date.

When I try to output the due date ([stored as RFC 3339][1]) as a string I get java.lang.IllegalArgumentException.

I am trying to use SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") to do this conversion.

My guess is that SimpleDateFormat is not the way to go but every other conversion I've tried has failed. I'm open to using Joda ISODateFormat but even that didn't work. I have included the relevant snippets of code.

My task (call item) class definition is:

    import com.google.api.client.util.DateTime;

    public class Item {
	
	Long id;
	String title;	
	String description;
	String extId1;
	Integer status;
	DateTime dateDue;
	DateTime dateLastEdit;
	DateTime dateCompleted;
		
	Item parent;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getDescription() {
		return description;
	}

	public void setNotes(String description) {
		this.description = description;
	}

	public String getExtId1() {
		return extId1;
	}

	public void setExtId1(String extId1) {
		this.extId1 = extId1;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public DateTime getDateDue() {
		return dateDue;
	}

	public void setDateDue(DateTime dateDue) {
		this.dateDue = dateDue;
	}

	public DateTime getDateLastEdit() {
		return dateLastEdit;
	}

	public void setDateLastEdit(DateTime dateLastEdit) {
		this.dateLastEdit = dateLastEdit;
	}

	public DateTime getDateCompleted() {
		return dateCompleted;
	}

	public void setDateCompleted(DateTime dateCompleted) {
		this.dateCompleted = dateCompleted;
	}

	public Item getParent() {
		return parent;
	}

	public void setParent(Item parent) {
		this.parent = parent;
	}
	
    }


To see this go wrong I demonstrate the doInBackground method where I try to output a returned date:

    @Override
    protected List<Item> doInBackground(Void... arg0) {
	  List<Item> itemList = new ArrayList<Item>();
	  DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
	  Log.v(TAG, "Start doInBackground...");
	  try {
		  List<String> result = new ArrayList<String>();
		  com.google.api.services.tasks.Tasks.TasksOperations.List listRequest = service.tasks().list("@default");
		  listRequest.setFields("items/title,items/notes,items/due");
		  List<Task> tasks = listRequest.execute().getItems();
		  if (tasks != null) {			  
			  for (Task task : tasks) {
				  result.add(task.getTitle());
				  Item item = new Item();				
				  item.setTitle(task.getTitle());
				  item.setNotes(task.getNotes());
				  DateTime due = task.getDue();
				  item.setDateDue(due);
				  Log.v(TAG, "Due date string: " + formatter.format(due));
				  itemList.add(item);
			  }
		  } else {
			  Log.v(TAG, "End doInBackground with no tasks");
			  result.add("No tasks.");
		  }		  
		  Log.v(TAG, "End doInBackground with tasks received");
		  return itemList;	 		 
	  } catch (IOException e) {
		  Log.v(TAG, "End doInBackground with IOException...");
		  tasksSample.handleGoogleException(e);
		  Item item = new Item();
		  item.setTitle(e.getMessage());
		  itemList.add(item);
		  return itemList;
		  //return Collections.singletonList(e.getMessage());
	  } catch (Exception e2) {
		  Log.v(TAG, "End doInBackground with generic exception...");
		  e2.printStackTrace();
		  Item item = new Item();
		  item.setTitle(e2.getMessage());
		  itemList.add(item);
		  return itemList;
	  } finally {
		  tasksSample.onRequestCompleted();
	  }
    }


  [1]: https://developers.google.com/google-apps/tasks/v1/reference/tasks#resource