get Current Time String - Android java.util

Android examples for java.util:Date Time

Description

get Current Time String

Demo Code

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;

public class Main {
  private final static ThreadLocal<SimpleDateFormat> dateFormater = new ThreadLocal<SimpleDateFormat>() {
    @Override//from  w w  w .  j a  v a2 s  .  co  m
    protected SimpleDateFormat initialValue() {
      return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
    }
  };

  public static String getCurTimeStr() {
    Calendar cal = Calendar.getInstance();
    String curDate = dateFormater.get().format(cal.getTime());
    return curDate;
  }

}

Related Tutorials