JAVA 时间 Date Long String类型之间的转换

Long 转date
Date result = new Date(param*1000);
Long 转String
String result = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(param* 1000));

String转date
Date result = new DateTime(param).toDate();
String转Long
Long result = Long.valueOf(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(param).getTime() / 1000);


Date转String
String result = new SimpleDateFormat("yyyyMMddHHmmss").format(param);
String result = new DateTime(param).toString("yyyy-MM-dd HH:mm:ss");
Date转Long
Long result = Long.valueOf(param.getTime() / 1000);

 

//获取昨天零点的时间
Calendar calendar = Calendar.getInstance();
calendar.set(calendar.get(Calendar.YEAR),calendar.get(Calendar.MONTH),calendar.get(Calendar.DAY_OF_MONTH)-1,0,0,0);
long StatisDate1 = calendar.getTime().getTime()/1000;
Date StatisDate2 = new Date(StatisDate1*1000);

posted on 2019-01-16 11:33  大孟子  阅读(8419)  评论(0编辑  收藏  举报

导航