Android Date Time Get getCurDateTime(String pattern)

Here you can find the source of getCurDateTime(String pattern)

Description

get Cur Date Time

Declaration

public static String getCurDateTime(String pattern) 

Method Source Code

//package com.java2s;

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Main {
    public static String DEFAULTFORMAT = "yyyy-MM-dd HH:mm:ss";

    public static String getCurDateTime() {
        return getCurDateTime(DEFAULTFORMAT);
    }//  w w w . ja va  2s  .c  o  m

    public static String getCurDateTime(String pattern) {
        return formatCalendar(Calendar.getInstance(), pattern);
    }

    public static String formatCalendar(Calendar calendar) {
        return formatCalendar(calendar, DEFAULTFORMAT);
    }

    public static String formatCalendar(Calendar calendar, String pattern) {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        // sdf.setTimeZone(TimeZone.getTimeZone(timeZone));
        return sdf.format(calendar.getTime());
    }
}

Related

  1. getCurDateTime()
  2. getCurrentDate(String time)
  3. getCurrentDate(long time)
  4. getDatetime()
  5. isNight()