title: How to parse date time in android
body: <pre><code>**Class Utils** 
  public static String getTimeAgo(String time) {
  
      String time_ago = "";
      try {
          // SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
          SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.getDefault());
          format.setTimeZone(TimeZone.getTimeZone("UTC"));
          Date past = format.parse(time);
          Date now = new Date();
          long seconds = TimeUnit.MILLISECONDS.toSeconds(now.getTime() - past.getTime());
          long minutes = TimeUnit.MILLISECONDS.toMinutes(now.getTime() - past.getTime());
          long hours = TimeUnit.MILLISECONDS.toHours(now.getTime() - past.getTime());
          long days = TimeUnit.MILLISECONDS.toDays(now.getTime() - past.getTime());
  
          if (seconds &lt; 60) {
              time_ago = seconds + " seconds ago";
          } else if (minutes &lt; 60) {
              time_ago = seconds + " minutes ago";
          } else if (hours &lt; 24) {
              time_ago = hours + " hours ago";
          } else {
              time_ago = days + " days ago";
          }
  
      } catch (Exception e) {
          e.printStackTrace();
      }
      return time_ago;
  }
  
  **Model**
  
  
  public class History{
      .....
      String mTime;
      public String getTime() {
      return Utils.getTimeAgo(mTime);
  }
  
  public void setTime(String mTime) {
      this.mTime = mTime;
  }
  </code></pre>
  
  <p>This is <strong>getView</strong> in <strong>Adapter</strong> </p>
  
  <pre><code>@Override
  public View getView(final int position, View view, final ViewGroup parent) {
      final ViewHolder holder;
      if (view == null) {
          LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          view = inflater.inflate(R.layout.item_history, null);
          holder = new ViewHolder();
          holder.mTvTitle = (TextView) view.findViewById(R.id.text_title);
          holder.mTvMediaName = (TextView) view.findViewById(R.id.text_mediaName);
          holder.mTvTime = (TextView) view.findViewById(R.id.text_time);
          holder.mImageUrl = (ImageView) view.findViewById(R.id.image_url);
          view.setTag(holder);
      } else {
          holder = (ViewHolder) view.getTag();
      }
      final History history = mListHistory.get(position);
      holder.mTvTitle.setText(history.getTitle());
      holder.mTvMediaName.setText(history.getMediaName());
      holder.mTvTime.setText(history.getTime());
      holder.mImageUrl.setImageResource(android.R.color.transparent);
      Picasso.with(mContext).load(history.getImageUrl())
          //.fit().centerInside()
          .into(holder.mImageUrl);
  
      return view;
  }
  </code></pre>
  
  <p>I set <code>String time = "2016-01-24T16:00:00.000Z";</code></p>
  
  <p><code>holder.mTvTime.setText(history.getTime());</code> not display values</p>
  
  <p>this is bug:</p>
  
  <blockquote>
    <p>java.text.ParseException: Unparseable date: "43 days ago" (at offset 2)</p>
  </blockquote>
  
  <p>Please. Help me!</p>