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