Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.annotation.SuppressLint;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {

    @SuppressLint("SimpleDateFormat")
    public static String getFreeCallTime(Date date) {
        SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
        return format.format(date);
    }

    public static String format(long timeInMillis, boolean fullTime) {
        SimpleDateFormat sdf = null;
        if (fullTime) {
            sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        } else {
            sdf = new SimpleDateFormat("yyyy-MM-dd");
        }

        String result = sdf.format(new Date(timeInMillis));
        return result;
    }

    public static String format(Date date, boolean fullTime) {
        SimpleDateFormat sdf = null;
        if (fullTime) {
            sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        } else {
            sdf = new SimpleDateFormat("yyyy-MM-dd");
        }

        String result = sdf.format(date);
        return result;
    }

    public static Date format(String date, boolean fullTime) {
        SimpleDateFormat sdf = null;
        if (fullTime) {
            sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        } else {
            sdf = new SimpleDateFormat("yyyy-MM-dd");
        }
        try {
            Date d = sdf.parse(date);
            return d;
        } catch (ParseException e) {
        }
        return null;
    }

    public static String format(String date, String dateFormat) {
        try {
            Date d = new Date(date);
            SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
            return sdf.format(d);
        } catch (Exception e) {
            return null;
        }
    }
}