Format long value to Date in 'Jul 2, 2013 @ 21:57' format - Android java.lang

Android examples for java.lang:long

Description

Format long value to Date in 'Jul 2, 2013 @ 21:57' format

Demo Code

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

public class Main {

  /**//from  w w w. j  a v  a2  s.  co  m
   * E.g. Jul 2, 2013 @ 21:57
   */
  public static String getDate(long ms) {
    Date date = new Date(ms);
    SimpleDateFormat sdf = new SimpleDateFormat("MMM d, yyyy '@' HH:mm", Locale.ENGLISH);

    // The timezone on the website is at GMT
    sdf.setTimeZone(TimeZone.getTimeZone("GMT"));

    return sdf.format(date);
  }

}

Related Tutorials