Date转换

来源:互联网 发布:淘宝网店费用 一年 编辑:程序博客网 时间:2024/06/10 02:48

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 转 sqlString datea = t_news.getDatea();//把toLocaleString得到的时间字符串变成日期类型通过 simpleDateFormat.parseSimpleDateFormat 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-23today(type="date"):2017-8-23today(type="time"):11:41:30today(type="both"):2017-8-23 11:41:30today(dateStyle="short"):17-8-23today(dateStyle="medium"):2017-8-23today(dateStyle="long"):2017823日today(dateStyle="full"):2017823日 星期三today(pattern="yyyy/MM/dd HH:mm:ss"):2017/08/23 11:41:30today(pattern="yyyy/MM/dd HH:mm:ss"):2017/08/23 11:41:30</body></html>*/
原创粉丝点击