Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

public class Main {
    public static final String FORMAT_ALL_DATE = "yyyy-MM-dd HH:mm:ss.SSS";
    public static final String FORMAT_TIME = "HH:mm:ss";
    private final static SimpleDateFormat sFORMAT = new SimpleDateFormat(FORMAT_ALL_DATE, Locale.CHINA);

    public static String generateTime(long time, boolean isLong) {
        Date date = new Date(time);
        sFORMAT.applyPattern(isLong ? FORMAT_ALL_DATE : FORMAT_TIME);
        String LgTime = null;
        try {
            LgTime = sFORMAT.format(date);
        } catch (Exception e) {
            try {
                SimpleDateFormat format = new SimpleDateFormat(isLong ? FORMAT_ALL_DATE : FORMAT_TIME,
                        Locale.CHINA);
                LgTime = format.format(new Date());
                e.printStackTrace();
            } catch (Exception e1) {
                e1.printStackTrace();
                LgTime = "";
            }
        }
        return LgTime;
    }
}