不多说看!
1 public class DateUtils { 2 3 public static final String datetimeFormater = "yyyy-MM-dd HH:mm:ss"; 4 public static final String dateFormater = "yyyy-MM-dd"; 5 6 // private static Date date ; 7 /** 8 * 格式化时间 9 */ 10 public static String formatDateTime(Date date) { 11 SimpleDateFormat df = new SimpleDateFormat(datetimeFormater); 12 return df.format(date); 13 } 14 15 /** 16 * 格式化时间戳 17 */ 18 public static String formatTimeMillion(String time) { 19 if(time != null){ 20 Date date = new Date(Long.parseLong(time) * 1000); 21 SimpleDateFormat format = new SimpleDateFormat(dateFormater); 22 String str = format.format(date); 23 return str; 24 } 25 return ""; 26 } 27 28 /** 29 * 根据具体的时间获得时间戳 30 * 31 * @param datetime 32 * @return 33 */ 34 public static long getLongTime(String datetime) { 35 SimpleDateFormat df = new SimpleDateFormat(datetimeFormater); 36 Date date = null; 37 try { 38 date = df.parse(datetime); 39 } catch (Exception e) { 40 e.printStackTrace(); 41 } 42 if(date != null){ 43 return date.getTime() / 1000; 44 }else{ 45 return 0; 46 } 47 } 48 49 /** 50 * 根据具体的时间获得时间戳 51 * 52 * @param datetime 53 * @return 54 */ 55 public static String getFormatTime(String time) { 56 DecimalFormat df = new DecimalFormat("#"); 57 double d = Double.parseDouble(time); 58 String result = df.format(d); 59 return formatTimeMillion(result); 60 } 61 62 public static String converTime(long time){ 63 Date d = new Date(time); 64 SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd hh:mm"); 65 return sdf.format(d); 66 } 67 }
时间: 2024-10-27 19:44:53