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);


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM