Date转换

util的date

public class Date1 {
   public static void main(String[] args) throws ParseException  {
    Date date=new Date();
    String localeString = date.toLocaleString();
    System.out.println(localeString);
    System.out.println(date.getTime());//1498481243639  2017-6-26 20:47:23
    SimpleDateFormat sdf=new SimpleDateFormat("yyyy;MM;dd;;hh;mm;ss");

    String ss=sdf.format(date);
//  System.out.println(ss);
//  String dd="2017-06-25 16:20:26";
//  Date date2 = sdf.parse(dd);
//  System.out.println(date2);
    Date date2=new Date(1498481243639l);
    System.out.println(date2);
}
}

public static void main(String[] args) throws ParseException {
    Date date=new Date();
    System.out.println(date.toLocaleString());
    long time = date.getTime();
    System.out.println(time);//1498464859777  从1970年0:0:0
    Date date2 = new Date(1498464859777l);
    System.out.println(date2);
    String dString="2015-12-12 20:53:12";
//将一个date类型装换成为一个字符串
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//  String string = simpleDateFormat.format(date);
//  System.out.println(string);
    //将一个字符串转换成一个date
    String dd="2017-06-25 16:20:26";
    Date date2 = simpleDateFormat.parse(dd);
    System.out.println(date2);

}

数据库中的date

util 转 sql
String datea = t_news.getDatea();
//把toLocaleString得到的时间字符串变成日期类型通过 simpleDateFormat.parse
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Date parse = simpleDateFormat.parse(datea);
//在通过日期的getTime()得到long time 最后再把这个放到timestamp交给数据库
Timestamp timestamp = new Timestamp(parse.getTime());
            pst.setTimestamp(4,timestamp);
            //

util 转 sql 日期
Date date = new Date();
Timestamp timestamp = new Timestamp(date.getTime());
util 转 sql 日期
String birthday = person.getBirthday();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
java.util.Date date = sdf.parse(birthday);
Date bt=new Date(date.getTime());

sql 转 util 日期
Timestamp timestamp = rs.getTimestamp(5);
String localeString = timestamp.toLocaleString();
sql 转 util 日期 
Date date = rs.getDate(3);
SimpleDateFormat simpleDateFormat =new SimpleDateFormat("yyyy-MM-dd");
String birthday = simpleDateFormat.format(date);


jsp中data

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>测试jstl格式化库</h1>
<hr>
<li>测试日期的格式化</li><br>
today(default):<fmt:formatDate value="${today}"/><br>
today(type="date"):<fmt:formatDate value="${today}" type="date"/><br>
today(type="time"):<fmt:formatDate value="${today}" type="time"/><br>
today(type="both"):<fmt:formatDate value="${today}" type="both"/><br>
today(dateStyle="short"):<fmt:formatDate value="${today}" dateStyle="short"/><br>
today(dateStyle="medium"):<fmt:formatDate value="${today}" dateStyle="medium"/><br>
today(dateStyle="long"):<fmt:formatDate value="${today}" dateStyle="long"/><br>
today(dateStyle="full"):<fmt:formatDate value="${today}" dateStyle="full"/><br>
today(pattern="yyyy/MM/dd HH:mm:ss"):<fmt:formatDate value="${today}" pattern="yyyy/MM/dd HH:mm:ss"/><br>
today(pattern="yyyy/MM/dd HH:mm:ss"):<fmt:formatDate value="${today}" pattern="yyyy/MM/dd HH:mm:ss" var="d"/><br>
${d }<br>

测试日期的格式化

today(default):2017-8-23
today(type="date"):2017-8-23
today(type="time"):11:41:30
today(type="both"):2017-8-23 11:41:30
today(dateStyle="short"):17-8-23
today(dateStyle="medium"):2017-8-23
today(dateStyle="long"):2017823日
today(dateStyle="full"):2017823日 星期三
today(pattern="yyyy/MM/dd HH:mm:ss"):2017/08/23 11:41:30
today(pattern="yyyy/MM/dd HH:mm:ss"):
2017/08/23 11:41:30
</body>
</html>*/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值