Android Date Time Get currentTimeToString(int format, String delimiter)

Here you can find the source of currentTimeToString(int format, String delimiter)

Description

current Time To String

Declaration

public static String currentTimeToString(int format, String delimiter) 

Method Source Code

//package com.java2s;

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

public class Main {
    private static final String[] SIMPLE_TIME_FORMAT = { "yyyy-MM-dd",
            "yyyy-MM-dd-HH", "yyyy-MM-dd-HH-mm", "yyyy-MM-dd-HH-mm-ss" };

    public static String currentTimeToString(int format, String delimiter) {
        return formatDate(new Date(), format, delimiter);
    }/* ww w  .j a  v  a 2s.  c o m*/

    public static String formatDate(long timeMilliSeconds, int format) {
        return formatDate(new Date(timeMilliSeconds), format, "");
    }

    public static String formatDate(long timeMilliSeconds, int format,
            String delimiter) {
        return formatDate(new Date(timeMilliSeconds), format, delimiter);
    }

    private static String formatDate(Date date, int format, String delimiter) {
        return formatDate(format, delimiter).format(date);
    }

    private static SimpleDateFormat formatDate(int format, String delimiter) {
        assert format >= 0 && format < SIMPLE_TIME_FORMAT.length;
        String formatString = SIMPLE_TIME_FORMAT[format];
        if (delimiter != null) {
            formatString = formatString.replace("-", delimiter);
        }
        return new SimpleDateFormat(formatString);
    }
}

Related

  1. getCurrentDate(long time)
  2. getDatetime()
  3. isNight()
  4. getDateDifference(Date thenDate)
  5. currentTimeLabel()
  6. getDate()
  7. getDate()