title: Android: Convert string to a time
body: <p>I am trying to convert a string that contains a time stamp to a time that is consistent with androids RelativeDateTimeString, so I can format it as a relative time. The time stamps that I get are in this format:</p>
  
  <pre><code>2011-08-17 04:57:38
  </code></pre>
  
  <p>I would like to take that string and pass it through my relative time function here:</p>
  
  <pre><code>    public void RelativeTime(Long time){
      String str = (String) DateUtils.getRelativeDateTimeString(
  
              this, // Suppose you are in an activity or other Context subclass
  
              time, // The time to display
  
              DateUtils.SECOND_IN_MILLIS, // The resolution. This will display only minutes 
                                // (no "3 seconds ago"
  
              DateUtils.WEEK_IN_MILLIS, // The maximum resolution at which the time will switch 
                               // to default date instead of spans. This will not 
                               // display "3 weeks ago" but a full date instead
  
              0); // Eventual flags
  
      toast(str);
  
  }
  </code></pre>
  
  <p>So the function should show a toast of "2 days ago" etc.</p>
  
  <p>EDIT: Sorry I have a toast function I've written as well.</p>
  
  <pre><code>public void toast(String text){
      Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
  }
  </code></pre>