get current Date Time and format it to yyyy-MM-dd HH:mm:ss - Android java.util

Android examples for java.util:Date Format

Description

get current Date Time and format it to yyyy-MM-dd HH:mm:ss

Demo Code


//package com.java2s;

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

import java.util.Locale;

public class Main {
    public static String getDateTime() {
        SimpleDateFormat dateFormat = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss", Locale.getDefault());
        Date date = new Date();
        return dateFormat.format(date);
    }/*from   ww  w .  j a va  2  s. co  m*/
}

Related Tutorials