时间转换



/**
 * @ 业务描述:
 * @ Package_name:com.ratel.easypoi
 * @ Project_name:easypoi
 * @ Author:ratelfu@qq.com
 * @ Create_time:2019-01-11 10:37
 * @ Copyright (c) ratelfu 版权所有
 */

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

public class DateUtils {
    public final static String Format_DateTime = "yyyy-MM-dd HH:mm:ss";
    public final static String Format_Date = "yyyy-MM-dd";
    public final static String Format_Time = "HH:mm:ss";
    public final static String Hours_Minute = "HH:mm";

    public static Long getLongByDateString(String dateString) {
        return Long.valueOf(dateString);
    }

    /**
     *  @param dateString "1545276566000"
     * @return 2018-12-20 11:29:26
     */
    public static String getDateTimeFormatByDateString(String dateString) {
        Date date = new Date(Long.valueOf(dateString));
        return new SimpleDateFormat(Format_DateTime).format(date);
    }

    /**
     *  @param dateString "1545276566000"
     *  @return 11:29:27
     */
    public static String getTimeFormatByDateString(String dateString) {
        Date date = new Date(Long.valueOf(dateString));
        return new SimpleDateFormat(Format_Time).format(date);
    }

    /**
     *  @param dateLong  1545276566000L
     *  @return 2018-12-20
     */
    public static String getDateFormatByLong(Long dateLong) {
        Date date = new Date(dateLong);
        return new SimpleDateFormat(Format_Date).format(date);
    }

    /**
     * @param dateLong   1545276566000L
     * @return 11:29
     */
    public static String getHoursMinuteFormatByDateString(Long dateLong) {
        Date date = new Date(dateLong);
        return new SimpleDateFormat(Hours_Minute).format(date);
    }

    /**
     *  @param dateString
     *  @param timeString
     *  @return 1544630399
     */
    public static Long getLongByDateString(String dateString, String timeString) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Long endDate = null;
        try {
            endDate = formatter.parse(dateString + " " + timeString).getTime() / 1000;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return endDate;
    }
}
 /**
     *
     * @param date Fri Jan 11 15:32:32 CST 2019
     * @return 2019-01-11
     */
    public static String getStringByDate(Date date){
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String dateString = formatter.format(date);
        return dateString;
    }

    /**
     * @param dateString 2018-12-20  / 2018-12-20 00:00:00
     * @return  Thu Dec 20 00:00:00 CST 2018
     */
    public static Date getDateByString(String dateString ){
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Date date=new Date();
        try {
           date = formatter.parse(dateString);

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值