Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.text.TextUtils;

import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

public class Main {
    public static String getFormatDate(final Date date, String type) {
        if (null == date || TextUtils.isEmpty(type)) {
            return null;
        }

        SimpleDateFormat sdf;
        try {
            sdf = new SimpleDateFormat(type, Locale.SIMPLIFIED_CHINESE);
        } catch (Exception e) {
            sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.SIMPLIFIED_CHINESE);
        }
        TimeZone timeZone = TimeZone.getTimeZone("GMT+8");
        sdf.setTimeZone(timeZone);
        return sdf.format(date);
    }
}