Posts Tagged ‘format’

Get date time in custom format

Basically, I use [Date] class to get current time and use [SimpleDateFormat] to format my own output.

Just a sample format:

private String getDateTime() {
    // get date time in custom format
    SimpleDateFormat sdf = new SimpleDateFormat("[yyyy/MM/dd - HH:mm:ss]");
    return sdf.format(new Date(appInfo.firstInstallTime));

Pete Houston

Categories: Tricks & Tips Tags: , ,