get current time in yyyyMMddHHmm format - Android java.util

Android examples for java.util:Date Format

Description

get current time in yyyyMMddHHmm format

Demo Code

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

public class Main {

  public static String getFormatSystime() {
    Date date = new Date();
    SimpleDateFormat sif = new SimpleDateFormat("yyyyMMddHHmm");
    String result = sif.format(date);
    StringBuffer sb = new StringBuffer();
    sb.append(result);// www.j  av  a 2s .c  o  m
    for (int i = 0; i < 16 - result.length(); i++) {
      sb.append("0");
    }
    return sb.toString().substring(1, 12);
  }

}

Related Tutorials