時間戳轉換日期
String date=orderInfo.getChangeTime().replace("null", ""); SimpleDateFormat sdf=new SimpleDateFormat("MM-dd"); String monthDate = sdf.format(new Date(Long.parseLong(date)*1000));
日期轉換時間戳
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Date date = format.parse("1478855251");
String time=date.getTime()/1000)
時間戳轉換星期
// b、使用SimpleDateFormat類 //根據日期取得星期幾 public static String getWeek(Date date){ SimpleDateFormat sdf = new SimpleDateFormat("EEEE"); String week = sdf.format(date); return week; } // 注:格式化字符串存在區分大小寫 // 對於創建SimpleDateFormat傳入的參數:EEEE代表星期,如“星期四”;MMMM代表中文月份,如“十一月”;MM代表月份,如“11”; // yyyy代表年份,如“2010”;dd代表天,如“25” // 2、取得日期是某年的第幾周 // 根據日期入得日期是某年的第幾周。 //取得日期是某年的第幾周 public static int getWeekOfYear(Date date){ Calendar cal = Calendar.getInstance(); cal.setTime(date); int week_of_year = cal.get(Calendar.WEEK_OF_YEAR); return week_of_year; } // 3、得到某年的某個月有多少天 // 已知年份和月份,取得該月有多少天。 //取得某個月有多少天 public static int getDaysOfMonth(int year,int month){ Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month-1); int days_of_month = cal.getActualMaximum(Calendar.DAY_OF_MONTH); return days_of_month; } // 4、取得兩個日期之間的相差多少天 // 已知兩個日期,計算它們之間相差多少天。 // 取得兩個日期之間的相差多少天 public static long getDaysBetween(Date date0, Date date1) { long daysBetween = (date0.getTime() - date1.getTime() + 1000000) / 86400000;// 86400000=3600*24*1000 用立即數,減少乘法計算的開銷 return daysBetween; }