DateFormat

public class DateFormat {

private static final SimpleDateFormat dateFormat = new SimpleDateFormat(
        "yyyy-MM-dd HH:mm:ss");

private static final SimpleDateFormat dateFormatNumber = new SimpleDateFormat(
        "yyyyMMddHHmmss");

public static String DateToString(Date date) {
    return dateFormat.format(date);
}

public static String DateToStringNumber(Date date) {
    return dateFormatNumber.format(date);
}

// 获取当前时间,long型
public static long currentTimeLong() {
    return new Date().getTime();
}

// 字符串日期转long
public static long StrDateToLong(String strDate) {
    if (strDate == "" || strDate == null) {
        return Long.parseLong("0");
    } else {
        return DateToLong(toDate(strDate));
    }
}

// 日期转long
public static long DateToLong(Date date) {
    return date.getTime();
}

// 获取当前时间,字符串形式
public static String currentTime() {
    Date date = new Date();
    return toString(date);
}

// 从字符串, 获取日期, 如time = "2016-3-16 4:12:16"
public static Date toDate(String time) {
    try {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = sdf.parse(time);

        return date;
    } catch (ParseException e) {
        return null;
    }
}

public static Date toDateNoHour(String time) {
    try {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        Date date = sdf.parse(time);

        return date;
    } catch (ParseException e) {
        return null;
    }
}
//定时时间
public static Date toTimingDate(String time,String format) {
    try {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        Date date = sdf.parse(time);

        return date;
    } catch (ParseException e) {
        return null;
    }
}
// 从long, 获取日期
public static Date LongtoDate(long millSec) {
    return new Date(millSec);
}

// 日期转化为字符串形式
public static String toString(Date date) {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    return format.format(date);
}

}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值