DateUtils工具类

/**  
 * @Title: Demo.java
 * @Package org.yuzheng.date
 * @Description: TODO
 * @author yuzheng.xia
 * @date 2014-1-8 下午10:44:40
 * @version V1.0  
 */
package org.yuzheng.utils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.sql.Timestamp;
/**
 * @ClassName: Demo
 * @Description: 对于时间日期的格式化转换
 * @author yuzheng.xia
 * @date 2014-1-8 下午10:44:40
 */
public class DateUtil
{


	//获得SimpleDateFormat
	public static SimpleDateFormat getSimpleDateFormat()
	{
		String pattern = "yyyy-MM-dd HH:mm:ss";
		return new SimpleDateFormat(pattern);
	}
	
	//将字符串转换成date
	public static Date convertDate(String time) throws Exception
	{
		return getSimpleDateFormat().parse(time);
	}
	
	//将long 转换成 date
	public static Date convertDate(long time) throws Exception
	{
		return getSimpleDateFormat().parse(getSimpleDateFormat().format(new Date(time)));
	}
	
	//将date类型的日期格式化
	public static String convertDateFormat(Date time) throws Exception
	{
		return getSimpleDateFormat().format(time);
	}
	
	//将date类型转换成Timestamp -- 接收一个Date类型的日期
    public static Timestamp convertTimestamp(Date time) throws Exception
    {

    	//传了一个String字符串日期 
    	return convertTimestamp(getSimpleDateFormat().format(time));
    }
    
    //将String类型转换成Timestamp -- 接收一个字符串日期
    public static Timestamp convertTimestamp(String time) throws Exception
    {

    	//传了一个long类型的日期
    	return new Timestamp(getSimpleDateFormat().parse(time).getTime());
    }
    
    //将long类型转换成Timestamp -- 接收一个long日期
    public static Timestamp convertTimestamp(long time) throws Exception
    {

    	//传了一个Date类型的日期
    	return convertTimestamp(new Date(time));
    }
	
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值