All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alibaba.jvm.sandbox.module.debug.util.SimpleDateFormatHolder Maven / Gradle / Ivy

There is a newer version: 1.4.0
Show newest version
package com.alibaba.jvm.sandbox.module.debug.util;

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

/**
 * SimpleDateFormat Holder
 *
 * @author [email protected]
 */
public class SimpleDateFormatHolder extends ThreadLocal {

    @Override
    protected SimpleDateFormat initialValue() {
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    }

    private static final SimpleDateFormatHolder instance = new SimpleDateFormatHolder();

    private SimpleDateFormatHolder() {
        //
    }

    public static SimpleDateFormatHolder getInstance() {
        return instance;
    }

    /**
     * 格式化日期
     *
     * @param date 日期
     * @return 格式化后字符串
     */
    public String format(Date date) {
        return getInstance().get().format(date);
    }


    /**
     * 格式化日期
     *
     * @param gmt gmt
     * @return 格式化后字符串
     */
    public String format(long gmt) {
        return getInstance().get().format(new Date(gmt));
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy