Get current date and time as a string. - Android java.util

Android examples for java.util:Date Format

Description

Get current date and time as a string.

Demo Code

/**/* w w w .  jav  a2  s .c  om*/
 * Copyright (c) 2012 Todoroo Inc
 *
 * See the file "LICENSE" for the full license governing this code.
 */
//package com.java2s;
import java.text.DateFormat;

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

public class Main {
    /**
     * Get current date and time as a string. Used for naming backup files.
     */
    public static String getDateForExport() {
        DateFormat df = new SimpleDateFormat("yyMMdd-HHmm");
        return df.format(new Date());
    }
}

Related Tutorials