Format Now Date to string in yyyy-MM-dd HH:mm:ss format - Android java.util

Android examples for java.util:Date Format

Description

Format Now Date to string in yyyy-MM-dd HH:mm:ss format

Demo Code

import android.util.Log;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class Main{

    public static Date getNowDate() {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss");
        String dateString = formatter.format(currentTime);
        ParsePosition pos = new ParsePosition(8);
        Date currentTime_2 = formatter.parse(dateString, pos);
        return currentTime_2;
    }//w  w w .  j  a v  a 2  s  . co  m

}

Related Tutorials