Create Short Time Range String - Android java.util

Android examples for java.util:Date Time

Description

Create Short Time Range String

Demo Code

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class Main {
  /** Separator for time range formatter */
  private static final String TIME_RANGE_SEPARATOR = " - ";

  /** The formatter for time only */
  private static final DateFormat TIME_PATTERN_SHORT_FORMATTER = new SimpleDateFormat("HH:mm", Locale.US);

  /**/*from  w ww  . j a  v a  2 s  .  com*/
   * Converts the 2 Date objects to the time string in the short range format
   */
  public static final String getShortTimeRangeString(Date start, Date end) {

    return new StringBuilder(TIME_PATTERN_SHORT_FORMATTER.format(start)).append(TIME_RANGE_SEPARATOR)
        .append(TIME_PATTERN_SHORT_FORMATTER.format(end)).toString();
  }

}

Related Tutorials