Android Time Format convertDateTime(long date, String format)

Here you can find the source of convertDateTime(long date, String format)

Description

convert Date Time

Declaration

@SuppressLint("SimpleDateFormat")
    public static String convertDateTime(long date, String format) 

Method Source Code

//package com.java2s;

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

import android.annotation.SuppressLint;

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

    @SuppressLint("SimpleDateFormat")
    public static long convertDateTime(String date) {
        return convertDateTime(date, null);
    }//  w  w w . ja va  2 s.  c  o  m

    @SuppressLint("SimpleDateFormat")
    public static long convertDateTime(String date, String format) {
        try {
            if (format == null) {
                format = DEFAULT_FORMAT_DATE;
            }

            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);

            return simpleDateFormat.parse(date).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return 0;
    }

    @SuppressLint("SimpleDateFormat")
    public static String convertDateTime(long date) {
        return convertDateTime(date, null);
    }

    @SuppressLint("SimpleDateFormat")
    public static String convertDateTime(long date, String format) {
        try {
            if (format == null) {
                format = DEFAULT_FORMAT_DATE;
            }

            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);

            return simpleDateFormat.format(new Date(date));
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }
}

Related

  1. dateTimeFormat(String dateTime)
  2. dateTimeFormat(String dateTime)
  3. formatDateTime(String date, String format)
  4. formatTime(long time)
  5. convertDateTime(String date, String format)
  6. getDateFromFormattedTimeStamp( String formattedTimeStamp)
  7. getFormattedTimeStamp(long millisSince1970)
  8. getRFC3339FormattedTime()
  9. get_current_date_time_format1_str()